blob: 7443788c0feb4742888c0e5f18afa3b2a5ccb01f [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Igor Murashkine7ee7632013-06-11 18:10:18 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "CameraDeviceClient"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
Jianing Weicb0652e2014-03-12 18:29:36 -070019//#define LOG_NDEBUG 0
Igor Murashkine7ee7632013-06-11 18:10:18 -070020
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070021#include <com_android_internal_camera_flags.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070022#include <cutils/properties.h>
Jayant Chowdhary12361932018-08-27 14:46:13 -070023#include <utils/CameraThreadState.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070024#include <utils/Log.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000025#include <utils/SessionConfigurationUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070026#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070027#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070028#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070029#include <camera/CameraUtils.h>
Austin Borger1c1bee02023-06-01 16:51:35 -070030#include <camera/StringUtils.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070031
32#include "common/CameraDeviceBase.h"
Emilian Peev35ae8262018-11-08 13:11:32 +000033#include "device3/Camera3Device.h"
34#include "device3/Camera3OutputStream.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070035#include "api2/CameraDeviceClient.h"
36
Emilian Peev00420d22018-02-05 21:33:13 +000037#include <camera_metadata_hidden.h>
38
Emilian Peev538c90e2018-12-17 18:03:19 +000039#include "DepthCompositeStream.h"
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080040#include "HeicCompositeStream.h"
Emilian Peev434248e2022-10-06 14:58:54 -070041#include "JpegRCompositeStream.h"
Emilian Peev538c90e2018-12-17 18:03:19 +000042
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080043// Convenience methods for constructing binder::Status objects for error returns
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070044
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080045#define STATUS_ERROR(errorCode, errorString) \
46 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070047 fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str())
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080048
49#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
50 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070051 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
52 __VA_ARGS__).c_str())
Igor Murashkine7ee7632013-06-11 18:10:18 -070053
54namespace android {
55using namespace camera2;
Austin Borgerea931242021-12-13 23:10:41 +000056using namespace camera3;
Emilian Peevf4816702020-04-03 15:44:51 -070057using camera3::camera_stream_rotation_t::CAMERA_STREAM_ROTATION_0;
Igor Murashkine7ee7632013-06-11 18:10:18 -070058
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070059namespace flags = com::android::internal::camera::flags;
60
Igor Murashkine7ee7632013-06-11 18:10:18 -070061CameraDeviceClientBase::CameraDeviceClientBase(
62 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080063 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger1c1bee02023-06-01 16:51:35 -070064 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080065 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070066 const std::optional<std::string>& clientFeatureId,
67 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080068 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070069 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070070 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070071 int clientPid,
72 uid_t clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070073 int servicePid,
74 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080075 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080076 IInterface::asBinder(remoteCallback),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080077 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080078 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080079 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080080 cameraId,
81 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070082 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080083 clientPid,
84 clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070085 servicePid,
86 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070087 mRemoteCallback(remoteCallback) {
88}
Igor Murashkine7ee7632013-06-11 18:10:18 -070089
90// Interface used by CameraService
91
92CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080093 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070094 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger1c1bee02023-06-01 16:51:35 -070095 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080096 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070097 const std::optional<std::string>& clientFeatureId,
98 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080099 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -0700100 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800101 int clientPid,
102 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700103 int servicePid,
Austin Borger18b30a72022-10-27 12:20:29 -0700104 bool overrideForPerfClass,
malikakash73125c62023-07-21 22:44:34 +0000105 bool overrideToPortrait,
106 const std::string& originalCameraId) :
Austin Borger74fca042022-05-23 12:41:21 -0700107 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
108 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700109 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
110 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700111 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700112 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700113 mRequestIdCounter(0),
malikakash73125c62023-07-21 22:44:34 +0000114 mOverrideForPerfClass(overrideForPerfClass),
115 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700116 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700117 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700118}
119
Emilian Peevbd8c5032018-02-14 23:05:40 +0000120status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700121 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000122 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800123}
124
125template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700126status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
127 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700128 ATRACE_CALL();
129 status_t res;
130
Emilian Peevbd8c5032018-02-14 23:05:40 +0000131 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700132 if (res != OK) {
133 return res;
134 }
135
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700136 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700137 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
138 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700139 if (res != OK) {
140 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
141 __FUNCTION__, strerror(-res), res);
142 return res;
143 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700144
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800145 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
146 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800147 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700148 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700149
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800150 const CameraMetadata &deviceInfo = mDevice->info();
151 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000152 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
153 if (physicalKeysEntry.count > 0) {
154 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
155 physicalKeysEntry.data.i32,
156 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
157 }
158
Emilian Peev2295df72021-11-12 18:14:10 -0800159 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
160 mDynamicProfileMap.emplace(
161 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
162 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
163 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800164 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800165 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800166 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800167 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800168 if (entry.count > 0 || ((entry.count % 3) != 0)) {
169 int64_t standardBitmap =
170 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
171 for (size_t i = 0; i < entry.count; i += 3) {
172 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800173 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800174 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
175 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800176 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800177 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800178 }
179 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800180 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
181 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800182 }
183 }
Emilian Peevef715e22022-05-19 17:44:33 -0700184 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
185 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800186 } else {
187 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
188 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
189 }
190 }
191 }
192
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700193 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800194 // Cache physical camera ids corresponding to this device and also the high
195 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700196 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800197 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700198 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800199 }
200 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700201 if (supportsUltraHighResolutionCapture(physicalId)) {
202 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800203 }
204 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700205 return OK;
206}
207
208CameraDeviceClient::~CameraDeviceClient() {
209}
210
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800211binder::Status CameraDeviceClient::submitRequest(
212 const hardware::camera2::CaptureRequest& request,
213 bool streaming,
214 /*out*/
215 hardware::camera2::utils::SubmitInfo *submitInfo) {
216 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
217 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700218}
219
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000221 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000222 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800223 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
224
Emilian Peev2f5d6012022-01-19 16:16:50 -0800225 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800226 // Trying to submit request with surface that wasn't created
227 if (idx == NAME_NOT_FOUND) {
228 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
229 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700230 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800231 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
232 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000233 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
234 != NAME_NOT_FOUND) {
235 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
236 currentStreamId);
237 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800238 }
239
240 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
241 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800242 outputStreamIds->push_back(streamSurfaceId.streamId());
243 }
244 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
245
246 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700247 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800248 streamSurfaceId.surfaceId());
249
Emilian Peevf873aa52018-01-26 14:58:28 +0000250 if (currentStreamId != nullptr) {
251 *currentStreamId = streamSurfaceId.streamId();
252 }
253
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800254 return binder::Status::ok();
255}
256
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800257static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
258 const Vector<int> &streamIdsForThisRequest) {
259 std::list<int> intersection;
260 for (auto &streamId : streamIdsForThisRequest) {
261 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
262 intersection.emplace_back(streamId);
263 }
264 }
265 return intersection;
266}
267
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800268binder::Status CameraDeviceClient::submitRequestList(
269 const std::vector<hardware::camera2::CaptureRequest>& requests,
270 bool streaming,
271 /*out*/
272 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700273 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700274 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700275
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800276 binder::Status res = binder::Status::ok();
277 status_t err;
278 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
279 return res;
280 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700281
282 Mutex::Autolock icl(mBinderSerializationLock);
283
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800284 if (!mDevice.get()) {
285 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
286 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700287
288 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800289 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700290 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800291 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700292 }
293
Emilian Peevaebbe412018-01-15 13:53:24 +0000294 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700295 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800296 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700297 uint32_t loopCounter = 0;
298
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800299 for (auto&& request: requests) {
300 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700301 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800302 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700303 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800304 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800305 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700306 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700307 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800308 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700309 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800310 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
311 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000312 } else if (request.mPhysicalCameraSettings.size() > 1) {
313 ALOGE("%s: Camera %s: reprocess requests not supported for "
314 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700315 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000316 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
317 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700318 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700319 }
320
Emilian Peevaebbe412018-01-15 13:53:24 +0000321 if (request.mPhysicalCameraSettings.empty()) {
322 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700323 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800324 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000325 "Request doesn't contain any settings");
326 }
327
328 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700329 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000330 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000331 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700332 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000333 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
334 "Invalid camera request settings");
335 }
336
Emilian Peevaebbe412018-01-15 13:53:24 +0000337 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800338 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700339 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800340 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
341 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700342 }
343
Jianing Wei90e59c92014-03-12 18:29:36 -0700344 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700345 * Write in the output stream IDs and map from stream ID to surface ID
346 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700347 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700348 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700349 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000350 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800351 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800352 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800353 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800354 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700355
Emilian Peevf873aa52018-01-26 14:58:28 +0000356 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800357 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000358 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800359 if (!res.isOk()) {
360 return res;
361 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000362
363 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
364 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700365 const std::string &requestedPhysicalId =
366 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
367 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800368 dynamicProfileBitmap |=
369 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000370 } else {
371 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
372 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700373 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800374 } else {
375 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
376 int streamId = request.mStreamIdxList.itemAt(i);
377 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700378
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800379 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
380 if (index < 0) {
381 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
382 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700383 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800384 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
385 "Request targets Surface that is not part of current capture session");
386 }
387
388 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
389 if ((size_t)surfaceIdx >= gbps.size()) {
390 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
391 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700392 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800393 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
394 "Request targets Surface has invalid surface index");
395 }
396
Emilian Peevf873aa52018-01-26 14:58:28 +0000397 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800398 if (!res.isOk()) {
399 return res;
400 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000401
Austin Borger1c1bee02023-06-01 16:51:35 -0700402 const std::string &requestedPhysicalId =
403 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
404 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800405 dynamicProfileBitmap |=
406 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
407 }
408 }
409
410 if (dynamicProfileBitmap !=
411 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
412 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
413 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
414 if ((dynamicProfileBitmap & i) == 0) {
415 continue;
416 }
417
418 const auto& it = mDynamicProfileMap.find(i);
419 if (it != mDynamicProfileMap.end()) {
420 if ((it->second == 0) ||
421 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
422 continue;
423 } else {
424 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
425 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700426 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800427 dynamicProfileBitmap);
428 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
429 "Request targets an unsupported dynamic range profile"
430 " combination");
431 }
432 } else {
433 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
434 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700435 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800436 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
437 "Request targets 10-bit Surface with unsupported dynamic range"
438 " profile");
439 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700440 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700441 }
442
Emilian Peevf873aa52018-01-26 14:58:28 +0000443 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
444 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000445 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000446 if (it.settings.isEmpty()) {
447 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700448 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000449 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
450 "Request settings are empty");
451 }
452
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800453 // Check whether the physical / logical stream has settings
454 // consistent with the sensor pixel mode(s) it was configured with.
455 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000456 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800457 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
458 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
459 outputStreamIds);
460 if (!request.mIsReprocess &&
461 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
462 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
463 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000464 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800465 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
466 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
467 "streams configured");
468 }
469 }
470
malikakash73125c62023-07-21 22:44:34 +0000471 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700472 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
473 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
474 mSupportedPhysicalRequestKeys.end();
475 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
476 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
477 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000478 if (physicalId != mDevice->getId()) {
479 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000480 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000481 if (found == requestedPhysicalIds.end()) {
482 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700483 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000484 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
485 "Invalid physical camera id");
486 }
Emilian Peev00420d22018-02-05 21:33:13 +0000487
488 if (!mSupportedPhysicalRequestKeys.empty()) {
489 // Filter out any unsupported physical request keys.
490 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
491 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
492 filteredParams.getAndLock());
493 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
494 filteredParams.unlock(meta);
495
496 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
497 camera_metadata_ro_entry entry = it.settings.find(keyIt);
498 if (entry.count > 0) {
499 filteredParams.update(entry);
500 }
501 }
502
malikakash73125c62023-07-21 22:44:34 +0000503 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700504 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000505 }
506 } else {
malikakash73125c62023-07-21 22:44:34 +0000507 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000508 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000509 }
510
511 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
512 // Callee logs
513 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
514 "Caller does not have permission to change restricted controls");
515 }
516
Emilian Peevaebbe412018-01-15 13:53:24 +0000517 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
518 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700519
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800520 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000521 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
522 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700523 }
524
Emilian Peevaebbe412018-01-15 13:53:24 +0000525 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
526 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700527 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800528 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700529 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800530 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700531
Emilian Peevaebbe412018-01-15 13:53:24 +0000532 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700533 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800534
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700535 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800536 if (!request.mUserTag.empty()) {
537 mUserTag = request.mUserTag;
538 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700539 camera_metadata_entry entry =
540 physicalSettingsList.begin()->metadata.find(
541 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
542 if (entry.count == 1) {
543 mVideoStabilizationMode = entry.data.u8[0];
544 }
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700545 if (flags::log_ultrawide_usage()) {
546 entry = physicalSettingsList.begin()->metadata.find(
547 ANDROID_CONTROL_ZOOM_RATIO);
548 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
549 mUsedUltraWide = true;
550 }
551 }
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000552 if (!mUsedSettingsOverrideZoom && flags::log_zoom_override_usage()) {
553 entry = physicalSettingsList.begin()->metadata.find(
554 ANDROID_CONTROL_SETTINGS_OVERRIDE);
555 if (entry.count == 1 && entry.data.i32[0] ==
556 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
557 mUsedSettingsOverrideZoom = true;
558 }
559 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700560 }
561 mRequestIdCounter++;
562
563 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700564 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
565 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800566 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700567 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800568 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700569 mCameraIdStr.c_str(), strerror(-err), err);
570 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800571 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700572 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700573 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700574 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700575 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700576 }
577 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700578 err = mDevice->captureList(metadataRequestList, surfaceMapList,
579 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800580 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700581 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800582 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700583 mCameraIdStr.c_str(), strerror(-err), err);
584 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800585 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700586 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700587 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800588 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700589 }
590
Austin Borger1c1bee02023-06-01 16:51:35 -0700591 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700592 return res;
593}
594
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800595binder::Status CameraDeviceClient::cancelRequest(
596 int requestId,
597 /*out*/
598 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700599 ATRACE_CALL();
600 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
601
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800602 status_t err;
603 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700604
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800605 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700606
607 Mutex::Autolock icl(mBinderSerializationLock);
608
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800609 if (!mDevice.get()) {
610 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
611 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700612
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700613 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700614 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700615 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
616 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
617 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
618 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700619 }
620
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800621 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700622
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800623 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800624 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700625 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700626 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800627 } else {
628 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800629 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700630 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700631 }
632
633 return res;
634}
635
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800636binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700637 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700638 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700639 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800640 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700641}
642
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100643binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700644 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800645 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700646 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700647 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
648 __FUNCTION__, mInputStream.configured ? 1 : 0,
649 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700650
Zhijun He0effd522016-03-04 10:22:27 -0800651 binder::Status res;
652 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
653
Emilian Peevcc0b7952020-01-07 13:54:47 -0800654 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700655 std::string msg = "Invalid offline stream ids";
656 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
657 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800658 }
659
Zhijun He0effd522016-03-04 10:22:27 -0800660 Mutex::Autolock icl(mBinderSerializationLock);
661
662 if (!mDevice.get()) {
663 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
664 }
665
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700666 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000667 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000668 if (!res.isOk()) {
669 return res;
670 }
671
672 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
673 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700674 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
675 mCameraIdStr.c_str());
676 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
677 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000678 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700679 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
680 mCameraIdStr.c_str(), strerror(-err), err);
681 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
682 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000683 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800684 offlineStreamIds->clear();
685 mDevice->getOfflineStreamIds(offlineStreamIds);
686
Emilian Peev2f5d6012022-01-19 16:16:50 -0800687 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000688 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
689 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800690 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700691 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
692 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
693 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
694 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000695 break;
696 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800697
698 // Composite streams can only support offline mode in case all individual internal
699 // streams are also supported.
700 std::vector<int> internalStreams;
701 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800702 offlineStreamIds->erase(
703 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800704 [&internalStreams] (int streamId) {
705 auto it = std::find(internalStreams.begin(), internalStreams.end(),
706 streamId);
707 if (it != internalStreams.end()) {
708 internalStreams.erase(it);
709 return true;
710 }
711
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800712 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800713 if (internalStreams.empty()) {
714 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
715 }
716 }
717
718 for (const auto& offlineStreamId : *offlineStreamIds) {
719 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000720 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700721
722 nsecs_t configureEnd = systemTime();
723 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700724 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700725 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000726 }
727
728 return res;
729}
730
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800731binder::Status CameraDeviceClient::isSessionConfigurationSupported(
732 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800733
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800734 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800735 binder::Status res;
736 status_t ret = OK;
737 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
738
739 Mutex::Autolock icl(mBinderSerializationLock);
740
741 if (!mDevice.get()) {
742 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
743 }
744
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800745 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700746 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
747 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
748 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800749 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700750
Emilian Peev35ae8262018-11-08 13:11:32 +0000751 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700752 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700753 sessionConfiguration, mOverrideForPerfClass, /*checkSessionParams*/false,
754 status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000755 switch (ret) {
756 case OK:
757 // Expected, do nothing.
758 break;
759 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700760 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000761 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700762 mCameraIdStr.c_str());
763 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
764 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000765 }
766
767 break;
768 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700769 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000770 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700771 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000772 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700773 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000774 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800775 }
776
777 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700778}
779
Bharatt Kukreja6dddeb72023-11-21 10:06:25 +0000780binder::Status CameraDeviceClient::getSessionCharacteristics(
781 const SessionConfiguration& sessionConfiguration,
782 /*out*/
783 hardware::camera2::impl::CameraMetadataNative* sessionCharacteristics) {
784 ATRACE_CALL();
785 binder::Status res;
786 status_t ret = OK;
787 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
788
789 Mutex::Autolock icl(mBinderSerializationLock);
790
791 if (!mDevice.get()) {
792 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
793 }
794
795 auto operatingMode = sessionConfiguration.getOperatingMode();
796 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
797 mCameraIdStr);
798 if (!res.isOk()) {
799 return res;
800 }
801
802 camera3::metadataGetter getMetadata = [this](const std::string &id,
803 bool /*overrideForPerfClass*/) {
804 return mDevice->infoPhysical(id);};
805 ret = mProviderManager->getSessionCharacteristics(mCameraIdStr.c_str(),
806 sessionConfiguration, mOverrideForPerfClass, getMetadata,
807 sessionCharacteristics);
808
809 switch (ret) {
810 case OK:
811 // Expected, do nothing.
812 break;
813 case INVALID_OPERATION: {
814 std::string msg = fmt::sprintf(
815 "Camera %s: Session characteristics query not supported!",
816 mCameraIdStr.c_str());
817 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
818 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
819 }
820
821 break;
822 default: {
823 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
824 strerror(-ret), ret);
825 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
826 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
827 msg.c_str());
828 }
829 }
830
831 return res;
832}
833
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800834binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700835 ATRACE_CALL();
836 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
837
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800838 binder::Status res;
839 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700840
841 Mutex::Autolock icl(mBinderSerializationLock);
842
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800843 if (!mDevice.get()) {
844 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
845 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700846
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700847 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700848 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700849 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000850 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700851
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700852 if (mInputStream.configured && mInputStream.id == streamId) {
853 isInput = true;
854 } else {
855 // Guard against trying to delete non-created streams
856 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700857 if (streamId == mStreamMap.valueAt(i).streamId()) {
858 surfaces.push_back(mStreamMap.keyAt(i));
859 }
860 }
861
862 // See if this stream is one of the deferred streams.
863 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
864 if (streamId == mDeferredStreams[i]) {
865 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700866 break;
867 }
868 }
869
Emilian Peev2f5d6012022-01-19 16:16:50 -0800870 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000871 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
872 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
873 compositeIndex = i;
874 break;
875 }
876 }
877
Shuzhen Wang0129d522016-10-30 22:43:41 -0700878 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700879 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
880 " stream created yet", mCameraIdStr.c_str(), streamId);
881 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
882 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700883 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700884 }
885
886 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800887 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700888
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800889 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700890 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
891 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
892 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
893 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800894 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700895 if (isInput) {
896 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700897 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700898 for (auto& surface : surfaces) {
899 mStreamMap.removeItem(surface);
900 }
901
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800902 mConfiguredOutputs.removeItem(streamId);
903
Shuzhen Wang0129d522016-10-30 22:43:41 -0700904 if (dIndex != NAME_NOT_FOUND) {
905 mDeferredStreams.removeItemsAt(dIndex);
906 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000907
908 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800909 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000910 status_t ret;
911 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
912 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700913 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
914 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
915 err, streamId);
916 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
917 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000918 }
919 mCompositeStreamMap.removeItemsAt(compositeIndex);
920 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800921 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
922 auto &streamSet = mapIt.second;
923 if (streamSet.find(streamId) != streamSet.end()) {
924 streamSet.erase(streamId);
925 break;
926 }
927 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700928 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700929 }
930
931 return res;
932}
933
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800934binder::Status CameraDeviceClient::createStream(
935 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
936 /*out*/
937 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700938 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700939
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800940 binder::Status res;
941 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700942
943 Mutex::Autolock icl(mBinderSerializationLock);
944
Shuzhen Wang0129d522016-10-30 22:43:41 -0700945 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
946 outputConfiguration.getGraphicBufferProducers();
947 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800948 bool deferredConsumer = outputConfiguration.isDeferred();
949 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700950 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800951 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800952 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800953 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800954 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800955 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800956 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700957 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000958 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700959
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700960 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000961 outputConfiguration.getSurfaceType());
962 if (!res.isOk()) {
963 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700964 }
Zhijun He5d677d12016-05-29 16:52:39 -0700965
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800966 if (!mDevice.get()) {
967 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
968 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700969 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800970 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000971 if (!res.isOk()) {
972 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800973 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000974
Shuzhen Wang0129d522016-10-30 22:43:41 -0700975 std::vector<sp<Surface>> surfaces;
976 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700977 status_t err;
978
979 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700980 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800981 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700982 }
983
Shuzhen Wang758c2152017-01-10 18:26:18 -0800984 OutputStreamInfo streamInfo;
985 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800986 const std::vector<int32_t> &sensorPixelModesUsed =
987 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700988 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700989 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700990 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800991 ssize_t index = mStreamMap.indexOfKey(binder);
992 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700993 std::string msg = std::string("Camera ") + mCameraIdStr
994 + ": Surface already has a stream created for it (ID "
995 + std::to_string(index) + ")";
996 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
997 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700998 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700999
Shuzhen Wang758c2152017-01-10 18:26:18 -08001000 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001001 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001002 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001003 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001004 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001005
1006 if (!res.isOk())
1007 return res;
1008
1009 if (!isStreamInfoValid) {
1010 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001011 }
1012
Shuzhen Wang758c2152017-01-10 18:26:18 -08001013 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -07001014 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -08001015 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001016
1017 // If mOverrideForPerfClass is true, do not fail createStream() for small
1018 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
1019 // closest possible supported size.
1020
Zhijun He125684a2015-12-26 15:07:30 -08001021 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +01001022 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001023 bool isDepthCompositeStream =
1024 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -08001025 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -07001026 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -08001027 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +00001028 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -08001029 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001030 sp<CompositeStream> compositeStream;
1031 if (isDepthCompositeStream) {
1032 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -08001033 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001034 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -07001035 } else {
1036 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001037 }
1038
Emilian Peev538c90e2018-12-17 18:03:19 +00001039 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
1040 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -07001041 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001042 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -07001043 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001044 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
1045 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001046 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -08001047 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00001048 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
1049 compositeStream);
1050 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001051 } else {
1052 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
1053 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001054 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001055 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -08001056 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -08001057 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001058 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
1059 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001060 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001061
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001062 if (err != OK) {
1063 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001064 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001065 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001066 streamInfo.dataSpace, strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001067 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001068 int i = 0;
1069 for (auto& binder : binders) {
1070 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1071 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001072 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1073 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001074 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001075
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001076 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001077 mStreamInfoMap[streamId] = streamInfo;
1078
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001079 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001080 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001081 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001082 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001083
Zhijun He5d677d12016-05-29 16:52:39 -07001084 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001085 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001086
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001087 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001088 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001089 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001090 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001091 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001092 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001093 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001094 }
1095
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001096 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001097 }
1098
1099 return res;
1100}
1101
Zhijun He5d677d12016-05-29 16:52:39 -07001102binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1103 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001104 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001105 /*out*/
1106 int* newStreamId) {
1107 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001108 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001109 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001110 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001111 status_t err;
1112 binder::Status res;
1113
1114 if (!mDevice.get()) {
1115 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1116 }
1117
1118 // Infer the surface info for deferred surface stream creation.
1119 width = outputConfiguration.getWidth();
1120 height = outputConfiguration.getHeight();
1121 surfaceType = outputConfiguration.getSurfaceType();
1122 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1123 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001124 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001125 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1126 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1127 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1128 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1129 }
1130 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001131 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001132 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001133 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1134 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001135 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1136 // Here, we override sensor pixel modes
1137 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1138 const std::vector<int32_t> &sensorPixelModesUsed =
1139 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001140 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001141 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001142 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001143 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1144 "sensor pixel modes used not valid for deferred stream");
1145 }
1146
Shuzhen Wang0129d522016-10-30 22:43:41 -07001147 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1148 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001149 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001150 &streamId, physicalCameraId,
1151 overriddenSensorPixelModesUsed,
1152 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001153 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001154 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001155 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001156 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001157 outputConfiguration.getMirrorMode(),
1158 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001159
1160 if (err != OK) {
1161 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001162 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001163 mCameraIdStr.c_str(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001164 } else {
1165 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1166 // a separate list to track. Once the deferred surface is set, this id will be
1167 // relocated to mStreamMap.
1168 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001169 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001170 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001171 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001172 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001173 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001174 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001175 outputConfiguration.getMirrorMode(),
1176 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001177
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001178 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001179 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001180 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001181
1182 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001183 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001184
1185 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001186 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001187 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001188 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001189 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001190 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001191 }
Zhijun He5d677d12016-05-29 16:52:39 -07001192 }
1193 return res;
1194}
1195
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001196binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001197 int32_t transform = 0;
1198 status_t err;
1199 binder::Status res;
1200
1201 if (!mDevice.get()) {
1202 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1203 }
1204
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001205 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001206 if (err != OK) {
1207 // Error logged by getRotationTransformLocked.
1208 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1209 "Unable to calculate rotation transform for new stream");
1210 }
1211
1212 err = mDevice->setStreamTransform(streamId, transform);
1213 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001214 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001215 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001216 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1217 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001218 }
1219
1220 return res;
1221}
Ruben Brunkbba75572014-11-20 17:29:50 -08001222
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001223binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001224 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001225 /*out*/
1226 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001227
1228 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001229 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1230 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001231
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001232 binder::Status res;
1233 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001234
1235 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001236
1237 if (!mDevice.get()) {
1238 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1239 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001240
1241 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001242 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1243 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1244 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1245 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001246 }
1247
1248 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001249 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001250 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001251 mInputStream.configured = true;
1252 mInputStream.width = width;
1253 mInputStream.height = height;
1254 mInputStream.format = format;
1255 mInputStream.id = streamId;
1256
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001257 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001258 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001259
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001260 *newStreamId = streamId;
1261 } else {
1262 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001263 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001264 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001265 }
1266
1267 return res;
1268}
1269
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001270binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001271
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001272 binder::Status res;
1273 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1274
1275 if (inputSurface == NULL) {
1276 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001277 }
1278
1279 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001280 if (!mDevice.get()) {
1281 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1282 }
1283 sp<IGraphicBufferProducer> producer;
1284 status_t err = mDevice->getInputBufferProducer(&producer);
1285 if (err != OK) {
1286 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001287 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001288 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001289 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001290 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001291 inputSurface->graphicBufferProducer = producer;
1292 }
1293 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001294}
1295
Emilian Peev40ead602017-09-26 15:46:36 +01001296binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1297 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1298 ATRACE_CALL();
1299
1300 binder::Status res;
1301 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1302
1303 Mutex::Autolock icl(mBinderSerializationLock);
1304
1305 if (!mDevice.get()) {
1306 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1307 }
1308
1309 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1310 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001311 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001312
Emilian Peev40ead602017-09-26 15:46:36 +01001313 auto producerCount = bufferProducers.size();
1314 if (producerCount == 0) {
1315 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1316 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1317 "bufferProducers must not be empty");
1318 }
1319
1320 // The first output is the one associated with the output configuration.
1321 // It should always be present, valid and the corresponding stream id should match.
1322 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1323 ssize_t index = mStreamMap.indexOfKey(binder);
1324 if (index == NAME_NOT_FOUND) {
1325 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1326 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1327 "OutputConfiguration is invalid");
1328 }
1329 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1330 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1331 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1332 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1333 "Stream id is invalid");
1334 }
1335
1336 std::vector<size_t> removedSurfaceIds;
1337 std::vector<sp<IBinder>> removedOutputs;
1338 std::vector<sp<Surface>> newOutputs;
1339 std::vector<OutputStreamInfo> streamInfos;
1340 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1341 for (auto &it : bufferProducers) {
1342 newOutputsMap.add(IInterface::asBinder(it), it);
1343 }
1344
1345 for (size_t i = 0; i < mStreamMap.size(); i++) {
1346 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1347 if (idx == NAME_NOT_FOUND) {
1348 if (mStreamMap[i].streamId() == streamId) {
1349 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1350 removedOutputs.push_back(mStreamMap.keyAt(i));
1351 }
1352 } else {
1353 if (mStreamMap[i].streamId() != streamId) {
1354 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1355 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1356 "Target Surface is invalid");
1357 }
1358 newOutputsMap.removeItemsAt(idx);
1359 }
1360 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001361 const std::vector<int32_t> &sensorPixelModesUsed =
1362 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001363 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001364 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001365 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001366 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001367 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001368
Emilian Peev40ead602017-09-26 15:46:36 +01001369 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1370 OutputStreamInfo outInfo;
1371 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001372 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001373 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001374 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001375 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001376 if (!res.isOk())
1377 return res;
1378
Emilian Peev40ead602017-09-26 15:46:36 +01001379 streamInfos.push_back(outInfo);
1380 newOutputs.push_back(surface);
1381 }
1382
1383 //Trivial case no changes required
1384 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1385 return binder::Status::ok();
1386 }
1387
1388 KeyedVector<sp<Surface>, size_t> outputMap;
1389 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1390 &outputMap);
1391 if (ret != OK) {
1392 switch (ret) {
1393 case NAME_NOT_FOUND:
1394 case BAD_VALUE:
1395 case -EBUSY:
1396 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1397 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001398 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001399 break;
1400 default:
1401 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1402 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001403 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001404 break;
1405 }
1406 } else {
1407 for (const auto &it : removedOutputs) {
1408 mStreamMap.removeItem(it);
1409 }
1410
1411 for (size_t i = 0; i < outputMap.size(); i++) {
1412 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1413 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1414 }
1415
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001416 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1417
Emilian Peev40ead602017-09-26 15:46:36 +01001418 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001419 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001420 }
1421
1422 return res;
1423}
1424
Igor Murashkine7ee7632013-06-11 18:10:18 -07001425// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001426binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1427 /*out*/
1428 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001429{
1430 ATRACE_CALL();
1431 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1432
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001433 binder::Status res;
1434 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001435
1436 Mutex::Autolock icl(mBinderSerializationLock);
1437
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001438 if (!mDevice.get()) {
1439 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1440 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001441
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001442 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001443 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001444 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1445 mCameraIdStr, templateId, &tempId);
1446 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001447
1448 CameraMetadata metadata;
1449 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001450 request != NULL) {
1451
1452 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001453 } else if (err == BAD_VALUE) {
1454 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001455 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001456 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001457
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001458 } else {
1459 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001460 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001461 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001462 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001463 return res;
1464}
1465
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001466binder::Status CameraDeviceClient::getCameraInfo(
1467 /*out*/
1468 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001469{
1470 ATRACE_CALL();
1471 ALOGV("%s", __FUNCTION__);
1472
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001473 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001474
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001475 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001476
1477 Mutex::Autolock icl(mBinderSerializationLock);
1478
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001479 if (!mDevice.get()) {
1480 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1481 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001482
Igor Murashkin099b4572013-07-12 17:52:16 -07001483 if (info != NULL) {
1484 *info = mDevice->info(); // static camera metadata
1485 // TODO: merge with device-specific camera metadata
1486 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001487
1488 return res;
1489}
1490
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001491binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001492{
1493 ATRACE_CALL();
1494 ALOGV("%s", __FUNCTION__);
1495
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001496 binder::Status res;
1497 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001498
1499 Mutex::Autolock icl(mBinderSerializationLock);
1500
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001501 if (!mDevice.get()) {
1502 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1503 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001504
1505 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001506 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001507 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001508 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001509 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001510 mCameraIdStr.c_str());
1511 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1512 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001513 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001514 status_t err = mDevice->waitUntilDrained();
1515 if (err != OK) {
1516 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001517 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001518 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001519 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001520 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001521 return res;
1522}
1523
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001524binder::Status CameraDeviceClient::flush(
1525 /*out*/
1526 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001527 ATRACE_CALL();
1528 ALOGV("%s", __FUNCTION__);
1529
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001530 binder::Status res;
1531 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001532
1533 Mutex::Autolock icl(mBinderSerializationLock);
1534
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001535 if (!mDevice.get()) {
1536 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1537 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001538
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001539 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001540 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001541 status_t err = mDevice->flush(lastFrameNumber);
1542 if (err != OK) {
1543 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001544 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1545 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001546 }
1547 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001548}
1549
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001550binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001551 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001552 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001553
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001554 binder::Status res;
1555 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001556
1557 Mutex::Autolock icl(mBinderSerializationLock);
1558
1559 // Guard against trying to prepare non-created streams
1560 ssize_t index = NAME_NOT_FOUND;
1561 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001562 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001563 index = i;
1564 break;
1565 }
1566 }
1567
1568 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001569 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1570 "with that ID exists", mCameraIdStr.c_str(), streamId);
1571 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1572 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001573 }
1574
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001575 // 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(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 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001587 return res;
1588}
1589
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001590binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001591 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001592 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001593
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001594 binder::Status res;
1595 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001596
1597 Mutex::Autolock icl(mBinderSerializationLock);
1598
1599 // Guard against trying to prepare non-created streams
1600 ssize_t index = NAME_NOT_FOUND;
1601 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001602 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001603 index = i;
1604 break;
1605 }
1606 }
1607
1608 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001609 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1610 "with that ID exists", mCameraIdStr.c_str(), streamId);
1611 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1612 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001613 }
1614
1615 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001616 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1617 mCameraIdStr.c_str(), maxCount);
1618 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1619 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001620 }
1621
1622 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1623 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001624 status_t err = mDevice->prepare(maxCount, streamId);
1625 if (err == BAD_VALUE) {
1626 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001627 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001628 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001629 } else if (err != OK) {
1630 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001631 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001632 strerror(-err), err);
1633 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001634
1635 return res;
1636}
1637
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001638binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001639 ATRACE_CALL();
1640 ALOGV("%s", __FUNCTION__);
1641
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001642 binder::Status res;
1643 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001644
1645 Mutex::Autolock icl(mBinderSerializationLock);
1646
1647 // Guard against trying to prepare non-created streams
1648 ssize_t index = NAME_NOT_FOUND;
1649 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001650 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001651 index = i;
1652 break;
1653 }
1654 }
1655
1656 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001657 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1658 "with that ID exists", mCameraIdStr.c_str(), streamId);
1659 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1660 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001661 }
1662
1663 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1664 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001665 status_t err = mDevice->tearDown(streamId);
1666 if (err == BAD_VALUE) {
1667 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001668 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001669 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001670 } else if (err != OK) {
1671 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001672 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001673 strerror(-err), err);
1674 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001675
1676 return res;
1677}
1678
Shuzhen Wang758c2152017-01-10 18:26:18 -08001679binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001680 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1681 ATRACE_CALL();
1682
1683 binder::Status res;
1684 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1685
1686 Mutex::Autolock icl(mBinderSerializationLock);
1687
Shuzhen Wang0129d522016-10-30 22:43:41 -07001688 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1689 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001690 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001691
Shuzhen Wang0129d522016-10-30 22:43:41 -07001692 if (bufferProducers.size() == 0) {
1693 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001694 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1695 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001696
Shuzhen Wang758c2152017-01-10 18:26:18 -08001697 // streamId should be in mStreamMap if this stream already has a surface attached
1698 // to it. Otherwise, it should be in mDeferredStreams.
1699 bool streamIdConfigured = false;
1700 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1701 for (size_t i = 0; i < mStreamMap.size(); i++) {
1702 if (mStreamMap.valueAt(i).streamId() == streamId) {
1703 streamIdConfigured = true;
1704 break;
1705 }
Zhijun He5d677d12016-05-29 16:52:39 -07001706 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001707 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1708 if (streamId == mDeferredStreams[i]) {
1709 deferredStreamIndex = i;
1710 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001711 }
1712
Shuzhen Wang758c2152017-01-10 18:26:18 -08001713 }
1714 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001715 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1716 "(ID %d)", mCameraIdStr.c_str(), streamId);
1717 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1718 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001719 }
1720
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001721 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001722 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1723 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1724 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1725 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001726 }
1727
Zhijun He5d677d12016-05-29 16:52:39 -07001728 if (!mDevice.get()) {
1729 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1730 }
1731
Shuzhen Wang758c2152017-01-10 18:26:18 -08001732 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001733 const std::vector<int32_t> &sensorPixelModesUsed =
1734 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001735 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001736 int32_t colorSpace = outputConfiguration.getColorSpace();
1737 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001738 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001739 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001740 for (auto& bufferProducer : bufferProducers) {
1741 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001742 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1743 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001744 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001745 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001746 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001747 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001748
1749 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001750 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001751 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001752 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001753 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001754
1755 if (!res.isOk())
1756 return res;
1757
1758 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001759 }
1760
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001761 // Gracefully handle case where finalizeOutputConfigurations is called
1762 // without any new surface.
1763 if (consumerSurfaces.size() == 0) {
1764 mStreamInfoMap[streamId].finalized = true;
1765 return res;
1766 }
1767
Zhijun He5d677d12016-05-29 16:52:39 -07001768 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001769 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001770 std::vector<int> consumerSurfaceIds;
1771 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001772 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001773 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1774 sp<IBinder> binder = IInterface::asBinder(
1775 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001776 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001777 binder.get(), streamId, consumerSurfaceIds[i]);
1778 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1779 }
1780 if (deferredStreamIndex != NAME_NOT_FOUND) {
1781 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001782 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001783 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001784 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001785 } else if (err == NO_INIT) {
1786 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001787 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001788 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001789 } else {
1790 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001791 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001792 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001793 }
1794
1795 return res;
1796}
1797
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001798binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001799 ATRACE_CALL();
1800 binder::Status res;
1801 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1802
1803 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001804 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1805 mCameraIdStr.c_str(), mode);
1806 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1807 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001808 }
1809
1810 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001811 BasicClient::setAudioRestriction(mode);
1812 return binder::Status::ok();
1813}
1814
1815binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1816 ATRACE_CALL();
1817 binder::Status res;
1818 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1819 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001820 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001821 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001822 }
1823 return binder::Status::ok();
1824}
1825
Ravneetaeb20dc2022-03-30 05:33:03 +00001826status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1827 return mDevice->setCameraServiceWatchdog(enabled);
1828}
1829
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001830status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001831 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1832
1833 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001834 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001835}
1836
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001837status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1838 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1839
1840 return mDevice->setAutoframingAutoBehavior(
1841 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1842}
1843
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001844bool CameraDeviceClient::supportsCameraMute() {
1845 return mDevice->supportsCameraMute();
1846}
1847
1848status_t CameraDeviceClient::setCameraMute(bool enabled) {
1849 return mDevice->setCameraMute(enabled);
1850}
1851
Shuzhen Wang16610a62022-12-15 22:38:07 -08001852void CameraDeviceClient::setStreamUseCaseOverrides(
1853 const std::vector<int64_t>& useCaseOverrides) {
1854 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1855}
1856
1857void CameraDeviceClient::clearStreamUseCaseOverrides() {
1858 mDevice->clearStreamUseCaseOverrides();
1859}
1860
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001861bool CameraDeviceClient::supportsZoomOverride() {
1862 return mDevice->supportsZoomOverride();
1863}
1864
1865status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1866 return mDevice->setZoomOverride(zoomOverride);
1867}
1868
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001869binder::Status CameraDeviceClient::switchToOffline(
1870 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001871 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001872 /*out*/
1873 sp<hardware::camera2::ICameraOfflineSession>* session) {
1874 ATRACE_CALL();
1875
1876 binder::Status res;
1877 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1878
1879 Mutex::Autolock icl(mBinderSerializationLock);
1880
1881 if (!mDevice.get()) {
1882 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1883 }
1884
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001885 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001886 std::string msg = "Offline surfaces must not be empty";
1887 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1888 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001889 }
1890
1891 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001892 std::string msg = "Invalid offline session";
1893 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1894 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001895 }
1896
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001897 std::vector<int32_t> offlineStreamIds;
1898 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001899 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001900 for (const auto& streamId : offlineOutputIds) {
1901 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001902 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001903 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001904 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001905 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1906 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001907 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001908
1909 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001910 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001911 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001912 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1913 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001914 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001915
Emilian Peev2f5d6012022-01-19 16:16:50 -08001916 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001917 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001918 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001919 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001920 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001921 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001922 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001923 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001924 if (isCompositeStream) {
1925 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1926 if (compositeIdx == NAME_NOT_FOUND) {
1927 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1928 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1929 "Unknown composite stream");
1930 }
1931
1932 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1933 &offlineStreamIds);
1934 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1935 mCompositeStreamMap.valueAt(compositeIdx));
1936 break;
1937 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001938 }
1939
Emilian Peev4697b642019-11-19 17:11:14 -08001940 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001941 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001942 }
1943 }
1944
1945 sp<CameraOfflineSessionBase> offlineSession;
1946 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1947 if (ret != OK) {
1948 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1949 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001950 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001951 }
1952
Emilian Peevcc0b7952020-01-07 13:54:47 -08001953 sp<CameraOfflineSessionClient> offlineClient;
1954 if (offlineSession.get() != nullptr) {
1955 offlineClient = new CameraOfflineSessionClient(sCameraService,
1956 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001957 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1958 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001959 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1960 }
1961
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001962 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001963 // A successful offline session switch must reset the current camera client
1964 // and release any resources occupied by previously configured streams.
1965 mStreamMap.clear();
1966 mConfiguredOutputs.clear();
1967 mDeferredStreams.clear();
1968 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001969 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001970 mCompositeStreamMap.clear();
1971 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001972 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001973 // In case we failed to register the offline client, ensure that it still initialized
1974 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001975 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001976
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001977 switch(ret) {
1978 case BAD_VALUE:
1979 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1980 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1981 case TIMED_OUT:
1982 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1983 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1984 default:
1985 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1986 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1987 strerror(-ret), ret);
1988 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001989 }
1990
1991 *session = offlineClient;
1992
1993 return binder::Status::ok();
1994}
1995
Igor Murashkine7ee7632013-06-11 18:10:18 -07001996status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001997 return BasicClient::dump(fd, args);
1998}
1999
2000status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002001 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07002002 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08002003 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08002004 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002005 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002006
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002007 dprintf(fd, " State:\n");
2008 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07002009 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002010 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07002011 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002012 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07002013 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07002014 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002015 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07002016 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002017 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07002018 mStreamMap.valueAt(i).streamId(),
2019 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07002020 }
Zhijun He5d677d12016-05-29 16:52:39 -07002021 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002022 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07002023 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002024 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07002025 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07002026 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08002027 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07002028 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002029 // TODO: print dynamic/request section from most recent requests
2030 mFrameProcessor->dump(fd, args);
2031
2032 return dumpDevice(fd, args);
2033}
2034
Austin Borger1c1bee02023-06-01 16:51:35 -07002035status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07002036 sp<CameraDeviceBase> device = mDevice;
2037 if (!device) {
2038 dprintf(out, " Device is detached.");
2039 return OK;
2040 }
2041 device->startWatchingTags(tags);
2042 return OK;
2043}
2044
2045status_t CameraDeviceClient::stopWatchingTags(int out) {
2046 sp<CameraDeviceBase> device = mDevice;
2047 if (!device) {
2048 dprintf(out, " Device is detached.");
2049 return OK;
2050 }
2051 device->stopWatchingTags();
2052 return OK;
2053}
2054
2055status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2056 sp<CameraDeviceBase> device = mDevice;
2057 if (!device) {
2058 return OK;
2059 }
2060 device->dumpWatchedEventsToVector(out);
2061 return OK;
2062}
2063
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002064void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002065 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002066 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002067 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002068
Emilian Peev538c90e2018-12-17 18:03:19 +00002069 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002070 {
2071 // Access to the composite stream map must be synchronized
2072 Mutex::Autolock l(mCompositeLock);
2073 // Composites can have multiple internal streams. Error notifications coming from such
2074 // internal streams may need to remain within camera service.
2075 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2076 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2077 resultExtras);
2078 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002079 }
2080
2081 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002082 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002083 }
2084}
2085
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002086void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2087 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2088
2089 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002090 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002091 }
2092
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002093 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002094 mStreamingRequestId = REQUEST_ID_NONE;
2095}
2096
Shuzhen Wang316781a2020-08-18 18:11:01 -07002097void CameraDeviceClient::notifyIdle(
2098 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2099 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002100 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002101 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002102
2103 if (remoteCb != 0) {
2104 remoteCb->onDeviceIdle();
2105 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002106
2107 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2108 {
2109 Mutex::Autolock l(mCompositeLock);
2110 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2111 hardware::CameraStreamStats compositeStats;
2112 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2113 if (compositeStats.mWidth > 0) {
2114 fullStreamStats.push_back(compositeStats);
2115 }
2116 }
2117 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002118 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Shuzhen Wang6e08d202023-10-24 20:27:14 +00002119 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide,
2120 mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002121}
2122
Jianing Weicb0652e2014-03-12 18:29:36 -07002123void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002124 nsecs_t timestamp) {
2125 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002126 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002127 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002128 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002129 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002130 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002131
Emilian Peev2f5d6012022-01-19 16:16:50 -08002132 // Access to the composite stream map must be synchronized
2133 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002134 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2135 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2136 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002137}
2138
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002139void CameraDeviceClient::notifyPrepared(int streamId) {
2140 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002141 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002142 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002143 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002144 remoteCb->onPrepared(streamId);
2145 }
2146}
2147
Shuzhen Wang9d066012016-09-30 11:30:20 -07002148void CameraDeviceClient::notifyRequestQueueEmpty() {
2149 // Thread safe. Don't bother locking.
2150 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2151 if (remoteCb != 0) {
2152 remoteCb->onRequestQueueEmpty();
2153 }
2154}
2155
Igor Murashkine7ee7632013-06-11 18:10:18 -07002156void CameraDeviceClient::detachDevice() {
2157 if (mDevice == 0) return;
2158
Shuzhen Wang316781a2020-08-18 18:11:01 -07002159 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002160 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002161
Emilian Peev7ee731f2022-02-08 14:55:52 -08002162 if (mFrameProcessor.get() != nullptr) {
2163 mFrameProcessor->removeListener(
2164 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2165 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2166 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002167 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002168 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002169 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002170 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002171
2172 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2173 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002174 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002175 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002176 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2177 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2178 }
2179
Igor Murashkine7ee7632013-06-11 18:10:18 -07002180 if ((code = mDevice->waitUntilDrained()) != OK) {
2181 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2182 code);
2183 }
2184 }
2185
Emilian Peev2f5d6012022-01-19 16:16:50 -08002186 {
2187 Mutex::Autolock l(mCompositeLock);
2188 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2189 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2190 if (ret != OK) {
2191 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2192 strerror(-ret), ret);
2193 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002194 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002195 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002196 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002197
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002198 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002199 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002200
2201 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002202 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002203}
2204
2205/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002206void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002207 ATRACE_CALL();
2208 ALOGV("%s", __FUNCTION__);
2209
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002210 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002211 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002212 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002213 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2214 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002215 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002216
Emilian Peev2f5d6012022-01-19 16:16:50 -08002217 // Access to the composite stream map must be synchronized
2218 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002219 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2220 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2221 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002222}
2223
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002224binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002225 if (mDisconnected) {
2226 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2227 "The camera device has been disconnected");
2228 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002229 status_t res = checkPid(checkLocation);
2230 return (res == OK) ? binder::Status::ok() :
2231 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2232 "Attempt to use camera from a different process than original client");
2233}
2234
Igor Murashkine7ee7632013-06-11 18:10:18 -07002235// TODO: move to Camera2ClientBase
2236bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2237
Jayant Chowdhary12361932018-08-27 14:46:13 -07002238 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002239 const int selfPid = getpid();
2240 camera_metadata_entry_t entry;
2241
2242 /**
2243 * Mixin default important security values
2244 * - android.led.transmit = defaulted ON
2245 */
2246 CameraMetadata staticInfo = mDevice->info();
2247 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2248 for(size_t i = 0; i < entry.count; ++i) {
2249 uint8_t led = entry.data.u8[i];
2250
2251 switch(led) {
2252 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2253 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2254 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2255 metadata.update(ANDROID_LED_TRANSMIT,
2256 &transmitDefault, 1);
2257 }
2258 break;
2259 }
2260 }
2261 }
2262
2263 // We can do anything!
2264 if (pid == selfPid) {
2265 return true;
2266 }
2267
2268 /**
2269 * Permission check special fields in the request
2270 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2271 */
2272 entry = metadata.find(ANDROID_LED_TRANSMIT);
2273 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2274 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002275 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002276 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002277 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002278 ALOGE("Permission Denial: "
2279 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2280 return false;
2281 }
2282 }
2283
2284 return true;
2285}
2286
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002287status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2288 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002289 ALOGV("%s: begin", __FUNCTION__);
2290
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002291 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002292 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002293}
2294
Austin Borger1c1bee02023-06-01 16:51:35 -07002295const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002296 if (mDevice->getId() == cameraId) {
2297 return mDevice->info();
2298 }
2299 return mDevice->infoPhysical(cameraId);
2300}
2301
Austin Borger1c1bee02023-06-01 16:51:35 -07002302bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002303 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002304 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002305}
2306
2307bool CameraDeviceClient::isSensorPixelModeConsistent(
2308 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2309 // First we get the sensorPixelMode from the settings metadata.
2310 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2311 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2312 if (sensorPixelModeEntry.count != 0) {
2313 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2314 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2315 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2316 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2317 __FUNCTION__, sensorPixelMode);
2318 return false;
2319 }
2320 }
2321 // Check whether each stream has max resolution allowed.
2322 bool consistent = true;
2323 for (auto it : streamIdList) {
2324 auto const streamInfoIt = mStreamInfoMap.find(it);
2325 if (streamInfoIt == mStreamInfoMap.end()) {
2326 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2327 return false;
2328 }
2329 consistent =
2330 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2331 streamInfoIt->second.sensorPixelModesUsed.end();
2332 if (!consistent) {
2333 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2334 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2335 ALOGE("sensor pixel mode used list: %i", m);
2336 }
2337 break;
2338 }
2339 }
2340
2341 return consistent;
2342}
2343
Igor Murashkine7ee7632013-06-11 18:10:18 -07002344} // namespace android