blob: 17a6dc34b5ae127f1c226be54786bd37f6f12a86 [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>
Igor Murashkine7ee7632013-06-11 18:10:18 -070023#include <utils/Log.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000024#include <utils/SessionConfigurationUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070025#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070026#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070027#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070028#include <camera/CameraUtils.h>
Austin Borger1c1bee02023-06-01 16:51:35 -070029#include <camera/StringUtils.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070030
31#include "common/CameraDeviceBase.h"
Emilian Peev35ae8262018-11-08 13:11:32 +000032#include "device3/Camera3Device.h"
33#include "device3/Camera3OutputStream.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070034#include "api2/CameraDeviceClient.h"
35
Emilian Peev00420d22018-02-05 21:33:13 +000036#include <camera_metadata_hidden.h>
37
Emilian Peev538c90e2018-12-17 18:03:19 +000038#include "DepthCompositeStream.h"
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080039#include "HeicCompositeStream.h"
Emilian Peev434248e2022-10-06 14:58:54 -070040#include "JpegRCompositeStream.h"
Emilian Peev538c90e2018-12-17 18:03:19 +000041
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080042// Convenience methods for constructing binder::Status objects for error returns
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070043
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080044#define STATUS_ERROR(errorCode, errorString) \
45 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070046 fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str())
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080047
48#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
49 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070050 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
51 __VA_ARGS__).c_str())
Igor Murashkine7ee7632013-06-11 18:10:18 -070052
53namespace android {
54using namespace camera2;
Austin Borgerea931242021-12-13 23:10:41 +000055using namespace camera3;
Emilian Peevf4816702020-04-03 15:44:51 -070056using camera3::camera_stream_rotation_t::CAMERA_STREAM_ROTATION_0;
Igor Murashkine7ee7632013-06-11 18:10:18 -070057
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070058namespace flags = com::android::internal::camera::flags;
59
Igor Murashkine7ee7632013-06-11 18:10:18 -070060CameraDeviceClientBase::CameraDeviceClientBase(
61 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080062 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger17e3ebe2024-02-14 15:02:11 -080063 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger2e772b82024-10-11 16:09:57 -070064 const AttributionSourceState& clientAttribution, int callingPid, bool systemNativeClient,
65 const std::string& cameraId, [[maybe_unused]] int api1CameraId, int cameraFacing,
66 int sensorOrientation, int servicePid, int rotationOverride)
67 : BasicClient(cameraService, IInterface::asBinder(remoteCallback),
68 attributionAndPermissionUtils, clientAttribution, callingPid, systemNativeClient,
69 cameraId, cameraFacing, sensorOrientation, servicePid, rotationOverride),
70 mRemoteCallback(remoteCallback) {}
Igor Murashkine7ee7632013-06-11 18:10:18 -070071
72// Interface used by CameraService
73
Austin Borger2e772b82024-10-11 16:09:57 -070074CameraDeviceClient::CameraDeviceClient(
75 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080076 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070077 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger17e3ebe2024-02-14 15:02:11 -080078 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger2e772b82024-10-11 16:09:57 -070079 const AttributionSourceState& clientAttribution, int callingPid, bool systemNativeClient,
80 const std::string& cameraId, int cameraFacing, int sensorOrientation, int servicePid,
81 bool overrideForPerfClass, int rotationOverride, const std::string& originalCameraId)
82 : Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper,
83 attributionAndPermissionUtils, clientAttribution, callingPid,
84 systemNativeClient, cameraId, /*API1 camera ID*/ -1, cameraFacing,
85 sensorOrientation, servicePid, overrideForPerfClass, rotationOverride),
86 mInputStream(),
87 mStreamingRequestId(REQUEST_ID_NONE),
88 mRequestIdCounter(0),
89 mOverrideForPerfClass(overrideForPerfClass),
90 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070091 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -070092 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -070093}
94
Emilian Peevbd8c5032018-02-14 23:05:40 +000095status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -070096 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +000097 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080098}
99
100template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700101status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
102 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700103 ATRACE_CALL();
104 status_t res;
105
Emilian Peevbd8c5032018-02-14 23:05:40 +0000106 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700107 if (res != OK) {
108 return res;
109 }
110
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700111 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700112 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
113 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700114 if (res != OK) {
115 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
116 __FUNCTION__, strerror(-res), res);
117 return res;
118 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700119
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800120 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
121 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800122 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700123 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700124
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800125 const CameraMetadata &deviceInfo = mDevice->info();
126 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000127 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
128 if (physicalKeysEntry.count > 0) {
129 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
130 physicalKeysEntry.data.i32,
131 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
132 }
133
Emilian Peev2295df72021-11-12 18:14:10 -0800134 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
135 mDynamicProfileMap.emplace(
136 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
137 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
138 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800139 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800140 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800141 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800142 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800143 if (entry.count > 0 || ((entry.count % 3) != 0)) {
144 int64_t standardBitmap =
145 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
146 for (size_t i = 0; i < entry.count; i += 3) {
147 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800148 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800149 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
150 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800151 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800152 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800153 }
154 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800155 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
156 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800157 }
158 }
Emilian Peevef715e22022-05-19 17:44:33 -0700159 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
160 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800161 } else {
162 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
163 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
164 }
165 }
166 }
167
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700168 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800169 // Cache physical camera ids corresponding to this device and also the high
170 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700171 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800172 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700173 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800174 }
175 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700176 if (supportsUltraHighResolutionCapture(physicalId)) {
177 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800178 }
179 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700180 return OK;
181}
182
183CameraDeviceClient::~CameraDeviceClient() {
184}
185
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800186binder::Status CameraDeviceClient::submitRequest(
187 const hardware::camera2::CaptureRequest& request,
188 bool streaming,
189 /*out*/
190 hardware::camera2::utils::SubmitInfo *submitInfo) {
191 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
192 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700193}
194
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800195binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000196 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000197 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800198 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
199
Emilian Peev2f5d6012022-01-19 16:16:50 -0800200 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800201 // Trying to submit request with surface that wasn't created
202 if (idx == NAME_NOT_FOUND) {
203 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
204 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700205 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800206 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
207 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000208 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
209 != NAME_NOT_FOUND) {
210 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
211 currentStreamId);
212 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800213 }
214
215 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
216 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800217 outputStreamIds->push_back(streamSurfaceId.streamId());
218 }
219 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
220
221 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700222 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800223 streamSurfaceId.surfaceId());
224
Emilian Peevf873aa52018-01-26 14:58:28 +0000225 if (currentStreamId != nullptr) {
226 *currentStreamId = streamSurfaceId.streamId();
227 }
228
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800229 return binder::Status::ok();
230}
231
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800232static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
233 const Vector<int> &streamIdsForThisRequest) {
234 std::list<int> intersection;
235 for (auto &streamId : streamIdsForThisRequest) {
236 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
237 intersection.emplace_back(streamId);
238 }
239 }
240 return intersection;
241}
242
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800243binder::Status CameraDeviceClient::submitRequestList(
244 const std::vector<hardware::camera2::CaptureRequest>& requests,
245 bool streaming,
246 /*out*/
247 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700248 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700249 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700250
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800251 binder::Status res = binder::Status::ok();
252 status_t err;
253 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
254 return res;
255 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700256
257 Mutex::Autolock icl(mBinderSerializationLock);
258
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800259 if (!mDevice.get()) {
260 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
261 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700262
263 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800264 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700265 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800266 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700267 }
268
Emilian Peevaebbe412018-01-15 13:53:24 +0000269 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Ryan Prichard09a5c6e2024-06-27 23:42:58 -0700270 std::list<SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800271 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700272 uint32_t loopCounter = 0;
273
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800274 for (auto&& request: requests) {
275 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700276 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800277 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700278 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800279 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800280 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700281 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700282 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800283 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700284 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800285 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
286 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000287 } else if (request.mPhysicalCameraSettings.size() > 1) {
288 ALOGE("%s: Camera %s: reprocess requests not supported for "
289 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700290 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000291 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
292 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700293 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700294 }
295
Emilian Peevaebbe412018-01-15 13:53:24 +0000296 if (request.mPhysicalCameraSettings.empty()) {
297 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700298 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800299 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000300 "Request doesn't contain any settings");
301 }
302
303 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700304 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000305 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000306 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700307 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000308 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
309 "Invalid camera request settings");
310 }
311
Emilian Peevaebbe412018-01-15 13:53:24 +0000312 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800313 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700314 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800315 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
316 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700317 }
318
Jianing Wei90e59c92014-03-12 18:29:36 -0700319 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700320 * Write in the output stream IDs and map from stream ID to surface ID
321 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700322 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700323 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700324 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000325 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800326 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800327 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800328 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800329 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700330
Emilian Peevf873aa52018-01-26 14:58:28 +0000331 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800332 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000333 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800334 if (!res.isOk()) {
335 return res;
336 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000337
338 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
339 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700340 const std::string &requestedPhysicalId =
341 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
342 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800343 dynamicProfileBitmap |=
344 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000345 } else {
346 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
347 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700348 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800349 } else {
350 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
351 int streamId = request.mStreamIdxList.itemAt(i);
352 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700353
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800354 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
355 if (index < 0) {
356 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
357 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700358 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800359 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
360 "Request targets Surface that is not part of current capture session");
361 }
362
363 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
364 if ((size_t)surfaceIdx >= gbps.size()) {
365 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
366 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700367 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800368 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
369 "Request targets Surface has invalid surface index");
370 }
371
Emilian Peevf873aa52018-01-26 14:58:28 +0000372 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800373 if (!res.isOk()) {
374 return res;
375 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000376
Austin Borger1c1bee02023-06-01 16:51:35 -0700377 const std::string &requestedPhysicalId =
378 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
379 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800380 dynamicProfileBitmap |=
381 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
382 }
383 }
384
385 if (dynamicProfileBitmap !=
386 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
387 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
388 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
389 if ((dynamicProfileBitmap & i) == 0) {
390 continue;
391 }
392
393 const auto& it = mDynamicProfileMap.find(i);
394 if (it != mDynamicProfileMap.end()) {
395 if ((it->second == 0) ||
396 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
397 continue;
398 } else {
399 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
400 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700401 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800402 dynamicProfileBitmap);
403 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
404 "Request targets an unsupported dynamic range profile"
405 " combination");
406 }
407 } else {
408 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
409 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700410 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800411 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
412 "Request targets 10-bit Surface with unsupported dynamic range"
413 " profile");
414 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700415 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700416 }
417
Emilian Peevf873aa52018-01-26 14:58:28 +0000418 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
419 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000420 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000421 if (it.settings.isEmpty()) {
422 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700423 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000424 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
425 "Request settings are empty");
426 }
427
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800428 // Check whether the physical / logical stream has settings
429 // consistent with the sensor pixel mode(s) it was configured with.
430 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000431 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800432 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
433 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
434 outputStreamIds);
435 if (!request.mIsReprocess &&
436 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
437 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
438 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000439 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800440 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
441 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
442 "streams configured");
443 }
444 }
445
malikakash73125c62023-07-21 22:44:34 +0000446 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700447 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
448 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
449 mSupportedPhysicalRequestKeys.end();
450 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
451 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
452 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000453 if (physicalId != mDevice->getId()) {
454 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000455 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000456 if (found == requestedPhysicalIds.end()) {
457 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700458 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000459 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
460 "Invalid physical camera id");
461 }
Emilian Peev00420d22018-02-05 21:33:13 +0000462
463 if (!mSupportedPhysicalRequestKeys.empty()) {
464 // Filter out any unsupported physical request keys.
465 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
466 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
467 filteredParams.getAndLock());
468 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
469 filteredParams.unlock(meta);
470
471 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
472 camera_metadata_ro_entry entry = it.settings.find(keyIt);
473 if (entry.count > 0) {
474 filteredParams.update(entry);
475 }
476 }
477
malikakash73125c62023-07-21 22:44:34 +0000478 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700479 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000480 }
481 } else {
malikakash73125c62023-07-21 22:44:34 +0000482 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000483 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000484 }
485
486 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
487 // Callee logs
488 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
489 "Caller does not have permission to change restricted controls");
490 }
491
Emilian Peevaebbe412018-01-15 13:53:24 +0000492 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
493 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700494
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800495 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000496 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
497 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700498 }
499
Emilian Peevaebbe412018-01-15 13:53:24 +0000500 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
501 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700502 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800503 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700504 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800505 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700506
Emilian Peevaebbe412018-01-15 13:53:24 +0000507 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700508 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800509
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700510 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800511 if (!request.mUserTag.empty()) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700512 mRunningSessionStats.mUserTag = request.mUserTag;
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800513 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700514 camera_metadata_entry entry =
515 physicalSettingsList.begin()->metadata.find(
516 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
517 if (entry.count == 1) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700518 mRunningSessionStats.mVideoStabilizationMode = entry.data.u8[0];
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700519 }
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700520
Shuzhen Wang968b23f2024-09-09 09:56:16 -0700521 if (!mRunningSessionStats.mUsedUltraWide) {
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700522 entry = physicalSettingsList.begin()->metadata.find(
523 ANDROID_CONTROL_ZOOM_RATIO);
524 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700525 mRunningSessionStats.mUsedUltraWide = true;
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700526 }
527 }
Shuzhen Wang0fccf0b2024-09-09 10:11:09 -0700528 if (!mRunningSessionStats.mUsedSettingsOverrideZoom) {
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000529 entry = physicalSettingsList.begin()->metadata.find(
530 ANDROID_CONTROL_SETTINGS_OVERRIDE);
531 if (entry.count == 1 && entry.data.i32[0] ==
532 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700533 mRunningSessionStats.mUsedSettingsOverrideZoom = true;
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000534 }
535 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700536 }
537 mRequestIdCounter++;
538
539 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700540 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
541 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800542 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700543 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800544 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700545 mCameraIdStr.c_str(), strerror(-err), err);
546 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800547 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700548 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700549 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700550 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700551 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700552 }
553 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700554 err = mDevice->captureList(metadataRequestList, surfaceMapList,
555 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800556 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700557 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800558 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700559 mCameraIdStr.c_str(), strerror(-err), err);
560 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800561 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700562 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700563 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800564 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700565 }
566
Austin Borger1c1bee02023-06-01 16:51:35 -0700567 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700568 return res;
569}
570
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800571binder::Status CameraDeviceClient::cancelRequest(
572 int requestId,
573 /*out*/
574 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700575 ATRACE_CALL();
576 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
577
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800578 status_t err;
579 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700580
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800581 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700582
583 Mutex::Autolock icl(mBinderSerializationLock);
584
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800585 if (!mDevice.get()) {
586 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
587 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700588
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700589 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700590 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700591 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
592 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
593 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
594 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700595 }
596
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800597 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700598
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800599 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800600 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700601 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700602 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800603 } else {
604 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800605 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700606 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700607 }
608
609 return res;
610}
611
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800612binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700613 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700614 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700615 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800616 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700617}
618
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100619binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700620 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800621 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700622 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700623 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
624 __FUNCTION__, mInputStream.configured ? 1 : 0,
625 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700626
Zhijun He0effd522016-03-04 10:22:27 -0800627 binder::Status res;
628 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
629
Emilian Peevcc0b7952020-01-07 13:54:47 -0800630 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700631 std::string msg = "Invalid offline stream ids";
632 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
633 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800634 }
635
Zhijun He0effd522016-03-04 10:22:27 -0800636 Mutex::Autolock icl(mBinderSerializationLock);
637
638 if (!mDevice.get()) {
639 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
640 }
641
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700642 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000643 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000644 if (!res.isOk()) {
645 return res;
646 }
647
648 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
649 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700650 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
651 mCameraIdStr.c_str());
652 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
653 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000654 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700655 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
656 mCameraIdStr.c_str(), strerror(-err), err);
657 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
658 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000659 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800660 offlineStreamIds->clear();
661 mDevice->getOfflineStreamIds(offlineStreamIds);
662
Emilian Peev2f5d6012022-01-19 16:16:50 -0800663 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000664 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
665 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800666 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700667 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
668 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
669 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
670 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000671 break;
672 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800673
674 // Composite streams can only support offline mode in case all individual internal
675 // streams are also supported.
676 std::vector<int> internalStreams;
677 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800678 offlineStreamIds->erase(
679 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800680 [&internalStreams] (int streamId) {
681 auto it = std::find(internalStreams.begin(), internalStreams.end(),
682 streamId);
683 if (it != internalStreams.end()) {
684 internalStreams.erase(it);
685 return true;
686 }
687
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800688 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800689 if (internalStreams.empty()) {
690 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
691 }
692 }
693
694 for (const auto& offlineStreamId : *offlineStreamIds) {
695 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000696 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700697
698 nsecs_t configureEnd = systemTime();
699 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700700 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700701 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000702 }
703
704 return res;
705}
706
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800707binder::Status CameraDeviceClient::isSessionConfigurationSupported(
708 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800709
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800710 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800711 binder::Status res;
712 status_t ret = OK;
713 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
714
715 Mutex::Autolock icl(mBinderSerializationLock);
716
717 if (!mDevice.get()) {
718 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
719 }
720
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800721 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700722 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
723 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
724 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800725 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700726
Emilian Peev35ae8262018-11-08 13:11:32 +0000727 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700728 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700729 sessionConfiguration, mOverrideForPerfClass, /*checkSessionParams*/false,
730 status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000731 switch (ret) {
732 case OK:
733 // Expected, do nothing.
734 break;
735 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700736 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000737 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700738 mCameraIdStr.c_str());
739 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
740 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000741 }
742
743 break;
744 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700745 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000746 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700747 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000748 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700749 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000750 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800751 }
752
753 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700754}
755
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800756binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700757 ATRACE_CALL();
758 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
759
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800760 binder::Status res;
761 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700762
763 Mutex::Autolock icl(mBinderSerializationLock);
764
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800765 if (!mDevice.get()) {
766 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
767 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700768
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700769 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700770 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700771 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000772 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700773
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700774 if (mInputStream.configured && mInputStream.id == streamId) {
775 isInput = true;
776 } else {
777 // Guard against trying to delete non-created streams
778 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700779 if (streamId == mStreamMap.valueAt(i).streamId()) {
780 surfaces.push_back(mStreamMap.keyAt(i));
781 }
782 }
783
784 // See if this stream is one of the deferred streams.
785 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
786 if (streamId == mDeferredStreams[i]) {
787 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700788 break;
789 }
790 }
791
Emilian Peev2f5d6012022-01-19 16:16:50 -0800792 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000793 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
794 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
795 compositeIndex = i;
796 break;
797 }
798 }
799
Shuzhen Wang0129d522016-10-30 22:43:41 -0700800 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700801 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
802 " stream created yet", mCameraIdStr.c_str(), streamId);
803 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
804 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700805 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700806 }
807
808 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800809 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700810
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800811 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700812 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
813 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
814 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
815 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800816 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700817 if (isInput) {
818 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700819 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700820 for (auto& surface : surfaces) {
821 mStreamMap.removeItem(surface);
822 }
823
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800824 mConfiguredOutputs.removeItem(streamId);
825
Shuzhen Wang0129d522016-10-30 22:43:41 -0700826 if (dIndex != NAME_NOT_FOUND) {
827 mDeferredStreams.removeItemsAt(dIndex);
828 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000829
830 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800831 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000832 status_t ret;
833 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
834 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700835 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
836 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
837 err, streamId);
838 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
839 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000840 }
841 mCompositeStreamMap.removeItemsAt(compositeIndex);
842 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800843 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
844 auto &streamSet = mapIt.second;
845 if (streamSet.find(streamId) != streamSet.end()) {
846 streamSet.erase(streamId);
847 break;
848 }
849 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700850 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700851 }
852
853 return res;
854}
855
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800856binder::Status CameraDeviceClient::createStream(
857 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
858 /*out*/
859 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700860 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700861
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800862 binder::Status res;
863 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700864
865 Mutex::Autolock icl(mBinderSerializationLock);
866
Shuzhen Wang0709c282024-02-12 09:09:32 -0800867 if (!outputConfiguration.isComplete()) {
868 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
869 "OutputConfiguration isn't valid!");
870 }
871
Shuzhen Wang0129d522016-10-30 22:43:41 -0700872 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
873 outputConfiguration.getGraphicBufferProducers();
874 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800875 bool deferredConsumer = outputConfiguration.isDeferred();
876 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700877 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800878 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800879 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800880 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800881 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800882 int timestampBase = outputConfiguration.getTimestampBase();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700883 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000884 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700885
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700886 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800887 outputConfiguration.getSurfaceType(), /*isConfigurationComplete*/true);
Emilian Peev35ae8262018-11-08 13:11:32 +0000888 if (!res.isOk()) {
889 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700890 }
Zhijun He5d677d12016-05-29 16:52:39 -0700891
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800892 if (!mDevice.get()) {
893 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
894 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700895 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800896 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000897 if (!res.isOk()) {
898 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800899 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000900
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700901 std::vector<SurfaceHolder> surfaces;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700902 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700903 status_t err;
904
905 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700906 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800907 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700908 }
909
Shuzhen Wang758c2152017-01-10 18:26:18 -0800910 OutputStreamInfo streamInfo;
911 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800912 const std::vector<int32_t> &sensorPixelModesUsed =
913 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700914 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700915 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700916 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800917 ssize_t index = mStreamMap.indexOfKey(binder);
918 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700919 std::string msg = std::string("Camera ") + mCameraIdStr
920 + ": Surface already has a stream created for it (ID "
921 + std::to_string(index) + ")";
922 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
923 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700924 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700925
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700926 int mirrorMode = outputConfiguration.getMirrorMode(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800927 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700928 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800929 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800930 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800931 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800932
933 if (!res.isOk())
934 return res;
935
936 if (!isStreamInfoValid) {
937 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700938 }
939
Shuzhen Wang758c2152017-01-10 18:26:18 -0800940 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700941 surfaces.push_back({surface, mirrorMode});
Ruben Brunkbba75572014-11-20 17:29:50 -0800942 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700943
944 // If mOverrideForPerfClass is true, do not fail createStream() for small
945 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
946 // closest possible supported size.
947
Zhijun He125684a2015-12-26 15:07:30 -0800948 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100949 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800950 bool isDepthCompositeStream =
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700951 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0].mSurface);
952 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(
953 surfaces[0].mSurface);
Emilian Peev434248e2022-10-06 14:58:54 -0700954 bool isJpegRCompositeStream =
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700955 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0].mSurface) &&
Emilian Peev15230142023-04-27 20:22:54 +0000956 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800957 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800958 sp<CompositeStream> compositeStream;
959 if (isDepthCompositeStream) {
960 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800961 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800962 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700963 } else {
964 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800965 }
966
Emilian Peev538c90e2018-12-17 18:03:19 +0000967 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
968 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700969 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800970 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700971 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000972 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
973 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000974 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800975 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700976 mCompositeStreamMap.add(
977 IInterface::asBinder(surfaces[0].mSurface->getIGraphicBufferProducer()),
Emilian Peev538c90e2018-12-17 18:03:19 +0000978 compositeStream);
979 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800980 } else {
981 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
982 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700983 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800984 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -0800985 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -0800986 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700987 streamInfo.timestampBase, streamInfo.colorSpace, useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000988 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700989
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800990 if (err != OK) {
991 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800992 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700993 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Henri Chataingbcb99452023-11-01 17:40:30 +0000994 static_cast<int>(streamInfo.dataSpace), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800995 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700996 int i = 0;
997 for (auto& binder : binders) {
998 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
999 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001000 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1001 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001002 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001003
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001004 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001005 mStreamInfoMap[streamId] = streamInfo;
1006
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001007 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001008 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001009 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001010 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001011
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001012 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001013 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001014 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001015 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001016 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001017 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001018 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001019 }
1020
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001021 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001022 }
1023
1024 return res;
1025}
1026
Zhijun He5d677d12016-05-29 16:52:39 -07001027binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1028 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001029 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001030 /*out*/
1031 int* newStreamId) {
1032 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001033 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001034 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001035 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001036 status_t err;
1037 binder::Status res;
1038
1039 if (!mDevice.get()) {
1040 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1041 }
Shuzhen Wang0709c282024-02-12 09:09:32 -08001042 if (!outputConfiguration.isComplete()) {
1043 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1044 "OutputConfiguration isn't valid!");
1045 }
Zhijun He5d677d12016-05-29 16:52:39 -07001046
1047 // Infer the surface info for deferred surface stream creation.
1048 width = outputConfiguration.getWidth();
1049 height = outputConfiguration.getHeight();
1050 surfaceType = outputConfiguration.getSurfaceType();
1051 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1052 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001053 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001054 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1055 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1056 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1057 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1058 }
1059 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001060 std::vector<SurfaceHolder> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001061 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001062 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1063 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001064 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1065 // Here, we override sensor pixel modes
1066 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1067 const std::vector<int32_t> &sensorPixelModesUsed =
1068 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001069 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001070 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001071 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001072 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1073 "sensor pixel modes used not valid for deferred stream");
1074 }
1075
Shuzhen Wang0129d522016-10-30 22:43:41 -07001076 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1077 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001078 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001079 &streamId, physicalCameraId,
1080 overriddenSensorPixelModesUsed,
1081 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001082 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001083 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001084 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001085 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001086 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001087
1088 if (err != OK) {
1089 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001090 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Henri Chataingbcb99452023-11-01 17:40:30 +00001091 mCameraIdStr.c_str(), width, height, format, static_cast<int>(dataSpace),
1092 strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001093 } else {
1094 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1095 // a separate list to track. Once the deferred surface is set, this id will be
1096 // relocated to mStreamMap.
1097 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001098 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001099 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001100 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001101 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001102 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001103 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001104 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001105
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001106 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001107 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001108 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001109
Zhijun He5d677d12016-05-29 16:52:39 -07001110 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001111 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001112 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001113 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001114 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001115 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001116 }
Zhijun He5d677d12016-05-29 16:52:39 -07001117 }
1118 return res;
1119}
1120
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001121binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001122 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001123 /*out*/
1124 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001125
1126 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001127 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1128 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001129
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001130 binder::Status res;
1131 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001132
1133 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001134
1135 if (!mDevice.get()) {
1136 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1137 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001138
1139 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001140 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1141 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1142 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1143 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001144 }
1145
1146 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001147 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001148 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001149 mInputStream.configured = true;
1150 mInputStream.width = width;
1151 mInputStream.height = height;
1152 mInputStream.format = format;
1153 mInputStream.id = streamId;
1154
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001155 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001156 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001157
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001158 *newStreamId = streamId;
1159 } else {
1160 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001161 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001162 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001163 }
1164
1165 return res;
1166}
1167
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001168binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001169
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001170 binder::Status res;
1171 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1172
1173 if (inputSurface == NULL) {
1174 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001175 }
1176
1177 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001178 if (!mDevice.get()) {
1179 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1180 }
Carlos Martinez Romero8e776102024-08-21 12:49:10 -07001181#if WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES
1182 sp<Surface> surface;
1183 status_t err = mDevice->getInputSurface(&surface);
1184 if (err != OK) {
1185 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1186 "Camera %s: Error getting input Surface: %s (%d)",
1187 mCameraIdStr.c_str(), strerror(-err), err);
1188 } else {
1189 inputSurface->name = toString16("CameraInput");
1190 inputSurface->graphicBufferProducer = surface->getIGraphicBufferProducer();
1191 }
1192#else
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001193 sp<IGraphicBufferProducer> producer;
1194 status_t err = mDevice->getInputBufferProducer(&producer);
1195 if (err != OK) {
1196 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001197 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001198 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001199 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001200 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001201 inputSurface->graphicBufferProducer = producer;
1202 }
Carlos Martinez Romero8e776102024-08-21 12:49:10 -07001203#endif
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001204 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001205}
1206
Emilian Peev40ead602017-09-26 15:46:36 +01001207binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1208 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1209 ATRACE_CALL();
1210
1211 binder::Status res;
1212 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1213
1214 Mutex::Autolock icl(mBinderSerializationLock);
1215
1216 if (!mDevice.get()) {
1217 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1218 }
Shuzhen Wang0709c282024-02-12 09:09:32 -08001219 if (!outputConfiguration.isComplete()) {
1220 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1221 "OutputConfiguration isn't valid!");
1222 }
Emilian Peev40ead602017-09-26 15:46:36 +01001223
1224 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1225 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001226 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001227
Emilian Peev40ead602017-09-26 15:46:36 +01001228 auto producerCount = bufferProducers.size();
1229 if (producerCount == 0) {
1230 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1231 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1232 "bufferProducers must not be empty");
1233 }
1234
1235 // The first output is the one associated with the output configuration.
1236 // It should always be present, valid and the corresponding stream id should match.
1237 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1238 ssize_t index = mStreamMap.indexOfKey(binder);
1239 if (index == NAME_NOT_FOUND) {
1240 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1241 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1242 "OutputConfiguration is invalid");
1243 }
1244 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1245 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1246 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1247 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1248 "Stream id is invalid");
1249 }
1250
1251 std::vector<size_t> removedSurfaceIds;
1252 std::vector<sp<IBinder>> removedOutputs;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001253 std::vector<SurfaceHolder> newOutputs;
Emilian Peev40ead602017-09-26 15:46:36 +01001254 std::vector<OutputStreamInfo> streamInfos;
1255 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1256 for (auto &it : bufferProducers) {
1257 newOutputsMap.add(IInterface::asBinder(it), it);
1258 }
1259
1260 for (size_t i = 0; i < mStreamMap.size(); i++) {
1261 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1262 if (idx == NAME_NOT_FOUND) {
1263 if (mStreamMap[i].streamId() == streamId) {
1264 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1265 removedOutputs.push_back(mStreamMap.keyAt(i));
1266 }
1267 } else {
1268 if (mStreamMap[i].streamId() != streamId) {
1269 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1270 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1271 "Target Surface is invalid");
1272 }
1273 newOutputsMap.removeItemsAt(idx);
1274 }
1275 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001276 const std::vector<int32_t> &sensorPixelModesUsed =
1277 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001278 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001279 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001280 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001281 int32_t colorSpace = outputConfiguration.getColorSpace();
Emilian Peev2295df72021-11-12 18:14:10 -08001282
Emilian Peev40ead602017-09-26 15:46:36 +01001283 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1284 OutputStreamInfo outInfo;
1285 sp<Surface> surface;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001286 int mirrorMode = outputConfiguration.getMirrorMode(newOutputsMap.valueAt(i));
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001287 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001288 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001289 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -08001290 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Emilian Peev40ead602017-09-26 15:46:36 +01001291 if (!res.isOk())
1292 return res;
1293
Emilian Peev40ead602017-09-26 15:46:36 +01001294 streamInfos.push_back(outInfo);
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001295 newOutputs.push_back({surface, mirrorMode});
Emilian Peev40ead602017-09-26 15:46:36 +01001296 }
1297
1298 //Trivial case no changes required
1299 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1300 return binder::Status::ok();
1301 }
1302
1303 KeyedVector<sp<Surface>, size_t> outputMap;
1304 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1305 &outputMap);
1306 if (ret != OK) {
1307 switch (ret) {
1308 case NAME_NOT_FOUND:
1309 case BAD_VALUE:
1310 case -EBUSY:
1311 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1312 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001313 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001314 break;
1315 default:
1316 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1317 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001318 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001319 break;
1320 }
1321 } else {
1322 for (const auto &it : removedOutputs) {
1323 mStreamMap.removeItem(it);
1324 }
1325
1326 for (size_t i = 0; i < outputMap.size(); i++) {
1327 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1328 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1329 }
1330
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001331 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1332
Emilian Peev40ead602017-09-26 15:46:36 +01001333 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001334 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001335 }
1336
1337 return res;
1338}
1339
Igor Murashkine7ee7632013-06-11 18:10:18 -07001340// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001341binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1342 /*out*/
1343 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001344{
1345 ATRACE_CALL();
1346 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1347
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001348 binder::Status res;
1349 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001350
1351 Mutex::Autolock icl(mBinderSerializationLock);
1352
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001353 if (!mDevice.get()) {
1354 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1355 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001356
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001357 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001358 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001359 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1360 mCameraIdStr, templateId, &tempId);
1361 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001362
1363 CameraMetadata metadata;
1364 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001365 request != NULL) {
1366
1367 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001368 } else if (err == BAD_VALUE) {
1369 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001370 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001371 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001372
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001373 } else {
1374 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001375 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001376 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001377 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001378 return res;
1379}
1380
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001381binder::Status CameraDeviceClient::getCameraInfo(
1382 /*out*/
1383 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001384{
1385 ATRACE_CALL();
1386 ALOGV("%s", __FUNCTION__);
1387
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001388 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001389
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001390 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001391
1392 Mutex::Autolock icl(mBinderSerializationLock);
1393
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001394 if (!mDevice.get()) {
1395 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1396 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001397
Igor Murashkin099b4572013-07-12 17:52:16 -07001398 if (info != NULL) {
1399 *info = mDevice->info(); // static camera metadata
1400 // TODO: merge with device-specific camera metadata
1401 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001402
1403 return res;
1404}
1405
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001406binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001407{
1408 ATRACE_CALL();
1409 ALOGV("%s", __FUNCTION__);
1410
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001411 binder::Status res;
1412 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001413
1414 Mutex::Autolock icl(mBinderSerializationLock);
1415
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001416 if (!mDevice.get()) {
1417 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1418 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001419
1420 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001421 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001422 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001423 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001424 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001425 mCameraIdStr.c_str());
1426 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1427 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001428 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001429 status_t err = mDevice->waitUntilDrained();
1430 if (err != OK) {
1431 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001432 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001433 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001434 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001435 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001436 return res;
1437}
1438
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001439binder::Status CameraDeviceClient::flush(
1440 /*out*/
1441 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001442 ATRACE_CALL();
1443 ALOGV("%s", __FUNCTION__);
1444
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001445 binder::Status res;
1446 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001447
1448 Mutex::Autolock icl(mBinderSerializationLock);
1449
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001450 if (!mDevice.get()) {
1451 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1452 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001453
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001454 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001455 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001456 status_t err = mDevice->flush(lastFrameNumber);
1457 if (err != OK) {
1458 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001459 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1460 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001461 }
1462 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001463}
1464
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001465binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001466 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001467 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001468
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001469 binder::Status res;
1470 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001471
1472 Mutex::Autolock icl(mBinderSerializationLock);
1473
1474 // Guard against trying to prepare non-created streams
1475 ssize_t index = NAME_NOT_FOUND;
1476 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001477 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001478 index = i;
1479 break;
1480 }
1481 }
1482
1483 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001484 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1485 "with that ID exists", mCameraIdStr.c_str(), streamId);
1486 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1487 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001488 }
1489
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001490 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1491 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001492 status_t err = mDevice->prepare(streamId);
1493 if (err == BAD_VALUE) {
1494 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001495 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001496 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001497 } else if (err != OK) {
1498 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001499 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001500 strerror(-err), err);
1501 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001502 return res;
1503}
1504
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001505binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001506 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001507 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001508
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001509 binder::Status res;
1510 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001511
1512 Mutex::Autolock icl(mBinderSerializationLock);
1513
1514 // Guard against trying to prepare non-created streams
1515 ssize_t index = NAME_NOT_FOUND;
1516 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001517 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001518 index = i;
1519 break;
1520 }
1521 }
1522
1523 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001524 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1525 "with that ID exists", mCameraIdStr.c_str(), streamId);
1526 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1527 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001528 }
1529
1530 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001531 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1532 mCameraIdStr.c_str(), maxCount);
1533 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1534 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001535 }
1536
1537 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1538 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001539 status_t err = mDevice->prepare(maxCount, streamId);
1540 if (err == BAD_VALUE) {
1541 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001542 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001543 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001544 } else if (err != OK) {
1545 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001546 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001547 strerror(-err), err);
1548 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001549
1550 return res;
1551}
1552
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001553binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001554 ATRACE_CALL();
1555 ALOGV("%s", __FUNCTION__);
1556
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001557 binder::Status res;
1558 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001559
1560 Mutex::Autolock icl(mBinderSerializationLock);
1561
1562 // Guard against trying to prepare non-created streams
1563 ssize_t index = NAME_NOT_FOUND;
1564 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001565 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001566 index = i;
1567 break;
1568 }
1569 }
1570
1571 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001572 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1573 "with that ID exists", mCameraIdStr.c_str(), streamId);
1574 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1575 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001576 }
1577
1578 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1579 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001580 status_t err = mDevice->tearDown(streamId);
1581 if (err == BAD_VALUE) {
1582 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001583 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001584 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001585 } else if (err != OK) {
1586 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001587 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001588 strerror(-err), err);
1589 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001590
1591 return res;
1592}
1593
Shuzhen Wang758c2152017-01-10 18:26:18 -08001594binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001595 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1596 ATRACE_CALL();
1597
1598 binder::Status res;
1599 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1600
1601 Mutex::Autolock icl(mBinderSerializationLock);
1602
Shuzhen Wang0709c282024-02-12 09:09:32 -08001603 if (!outputConfiguration.isComplete()) {
1604 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1605 "OutputConfiguration isn't valid!");
1606 }
1607
Shuzhen Wang0129d522016-10-30 22:43:41 -07001608 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1609 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001610 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001611
Shuzhen Wang0129d522016-10-30 22:43:41 -07001612 if (bufferProducers.size() == 0) {
1613 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001614 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1615 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001616
Shuzhen Wang758c2152017-01-10 18:26:18 -08001617 // streamId should be in mStreamMap if this stream already has a surface attached
1618 // to it. Otherwise, it should be in mDeferredStreams.
1619 bool streamIdConfigured = false;
1620 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1621 for (size_t i = 0; i < mStreamMap.size(); i++) {
1622 if (mStreamMap.valueAt(i).streamId() == streamId) {
1623 streamIdConfigured = true;
1624 break;
1625 }
Zhijun He5d677d12016-05-29 16:52:39 -07001626 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001627 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1628 if (streamId == mDeferredStreams[i]) {
1629 deferredStreamIndex = i;
1630 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001631 }
1632
Shuzhen Wang758c2152017-01-10 18:26:18 -08001633 }
1634 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001635 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1636 "(ID %d)", mCameraIdStr.c_str(), streamId);
1637 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1638 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001639 }
1640
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001641 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001642 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1643 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1644 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1645 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001646 }
1647
Zhijun He5d677d12016-05-29 16:52:39 -07001648 if (!mDevice.get()) {
1649 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1650 }
1651
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001652 std::vector<SurfaceHolder> consumerSurfaceHolders;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001653 const std::vector<int32_t> &sensorPixelModesUsed =
1654 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001655 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001656 int32_t colorSpace = outputConfiguration.getColorSpace();
1657 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001658 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001659 for (auto& bufferProducer : bufferProducers) {
1660 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001661 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1662 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001663 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001664 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001665 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001666 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001667
1668 sp<Surface> surface;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001669 int mirrorMode = outputConfiguration.getMirrorMode(bufferProducer);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001670 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001671 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001672 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -08001673 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001674
1675 if (!res.isOk())
1676 return res;
1677
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001678 consumerSurfaceHolders.push_back({surface, mirrorMode});
Zhijun He5d677d12016-05-29 16:52:39 -07001679 }
1680
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001681 // Gracefully handle case where finalizeOutputConfigurations is called
1682 // without any new surface.
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001683 if (consumerSurfaceHolders.size() == 0) {
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001684 mStreamInfoMap[streamId].finalized = true;
1685 return res;
1686 }
1687
Zhijun He5d677d12016-05-29 16:52:39 -07001688 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001689 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001690 std::vector<int> consumerSurfaceIds;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001691 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaceHolders, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001692 if (err == OK) {
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001693 for (size_t i = 0; i < consumerSurfaceHolders.size(); i++) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001694 sp<IBinder> binder = IInterface::asBinder(
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001695 consumerSurfaceHolders[i].mSurface->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001696 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001697 binder.get(), streamId, consumerSurfaceIds[i]);
1698 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1699 }
1700 if (deferredStreamIndex != NAME_NOT_FOUND) {
1701 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001702 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001703 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001704 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001705 } else if (err == NO_INIT) {
1706 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001707 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001708 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001709 } else {
1710 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001711 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001712 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001713 }
1714
1715 return res;
1716}
1717
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001718binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001719 ATRACE_CALL();
1720 binder::Status res;
1721 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1722
1723 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001724 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1725 mCameraIdStr.c_str(), mode);
1726 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1727 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001728 }
1729
1730 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001731 BasicClient::setAudioRestriction(mode);
1732 return binder::Status::ok();
1733}
1734
1735binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1736 ATRACE_CALL();
1737 binder::Status res;
1738 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1739 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001740 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001741 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001742 }
1743 return binder::Status::ok();
1744}
1745
Ravneetaeb20dc2022-03-30 05:33:03 +00001746status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1747 return mDevice->setCameraServiceWatchdog(enabled);
1748}
1749
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001750status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001751 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1752
1753 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001754 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001755}
1756
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001757status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1758 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1759
1760 return mDevice->setAutoframingAutoBehavior(
1761 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1762}
1763
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001764bool CameraDeviceClient::supportsCameraMute() {
1765 return mDevice->supportsCameraMute();
1766}
1767
1768status_t CameraDeviceClient::setCameraMute(bool enabled) {
1769 return mDevice->setCameraMute(enabled);
1770}
1771
Shuzhen Wang16610a62022-12-15 22:38:07 -08001772void CameraDeviceClient::setStreamUseCaseOverrides(
1773 const std::vector<int64_t>& useCaseOverrides) {
1774 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1775}
1776
1777void CameraDeviceClient::clearStreamUseCaseOverrides() {
1778 mDevice->clearStreamUseCaseOverrides();
1779}
1780
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001781bool CameraDeviceClient::supportsZoomOverride() {
1782 return mDevice->supportsZoomOverride();
1783}
1784
1785status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1786 return mDevice->setZoomOverride(zoomOverride);
1787}
1788
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001789binder::Status CameraDeviceClient::switchToOffline(
1790 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001791 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001792 /*out*/
1793 sp<hardware::camera2::ICameraOfflineSession>* session) {
1794 ATRACE_CALL();
1795
1796 binder::Status res;
1797 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1798
1799 Mutex::Autolock icl(mBinderSerializationLock);
1800
1801 if (!mDevice.get()) {
1802 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1803 }
1804
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001805 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001806 std::string msg = "Offline surfaces must not be empty";
1807 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1808 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001809 }
1810
1811 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001812 std::string msg = "Invalid offline session";
1813 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1814 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001815 }
1816
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001817 std::vector<int32_t> offlineStreamIds;
1818 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001819 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001820 for (const auto& streamId : offlineOutputIds) {
1821 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001822 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001823 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001824 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001825 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1826 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001827 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001828
1829 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001830 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001831 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001832 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1833 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001834 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001835
Emilian Peev2f5d6012022-01-19 16:16:50 -08001836 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001837 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001838 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001839 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001840 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001841 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001842 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001843 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001844 if (isCompositeStream) {
1845 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1846 if (compositeIdx == NAME_NOT_FOUND) {
1847 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1848 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1849 "Unknown composite stream");
1850 }
1851
1852 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1853 &offlineStreamIds);
1854 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1855 mCompositeStreamMap.valueAt(compositeIdx));
1856 break;
1857 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001858 }
1859
Emilian Peev4697b642019-11-19 17:11:14 -08001860 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001861 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001862 }
1863 }
1864
1865 sp<CameraOfflineSessionBase> offlineSession;
1866 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1867 if (ret != OK) {
1868 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1869 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001870 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001871 }
1872
Emilian Peevcc0b7952020-01-07 13:54:47 -08001873 sp<CameraOfflineSessionClient> offlineClient;
1874 if (offlineSession.get() != nullptr) {
Austin Borger2e772b82024-10-11 16:09:57 -07001875 offlineClient = new CameraOfflineSessionClient(
1876 sCameraService, offlineSession, offlineCompositeStreamMap, cameraCb,
1877 mAttributionAndPermissionUtils, mClientAttribution, mCallingPid, mCameraIdStr,
1878 mCameraFacing, mOrientation, mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001879 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1880 }
1881
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001882 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001883 // A successful offline session switch must reset the current camera client
1884 // and release any resources occupied by previously configured streams.
1885 mStreamMap.clear();
1886 mConfiguredOutputs.clear();
1887 mDeferredStreams.clear();
1888 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001889 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001890 mCompositeStreamMap.clear();
1891 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001892 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001893 // In case we failed to register the offline client, ensure that it still initialized
1894 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001895 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001896
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001897 switch(ret) {
1898 case BAD_VALUE:
1899 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1900 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1901 case TIMED_OUT:
1902 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1903 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1904 default:
1905 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1906 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1907 strerror(-ret), ret);
1908 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001909 }
1910
1911 *session = offlineClient;
1912
1913 return binder::Status::ok();
1914}
1915
Igor Murashkine7ee7632013-06-11 18:10:18 -07001916status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001917 return BasicClient::dump(fd, args);
1918}
1919
1920status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001921 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001922 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001923 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001924 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Austin Borger2e772b82024-10-11 16:09:57 -07001925 dprintf(fd, " Current client UID %u\n", getClientUid());
Igor Murashkine7ee7632013-06-11 18:10:18 -07001926
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001927 dprintf(fd, " State:\n");
1928 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001929 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001930 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001931 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001932 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001933 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001934 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001935 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001936 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001937 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001938 mStreamMap.valueAt(i).streamId(),
1939 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001940 }
Zhijun He5d677d12016-05-29 16:52:39 -07001941 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001942 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001943 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001944 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001945 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001946 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001947 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001948 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001949 // TODO: print dynamic/request section from most recent requests
1950 mFrameProcessor->dump(fd, args);
1951
1952 return dumpDevice(fd, args);
1953}
1954
Austin Borger1c1bee02023-06-01 16:51:35 -07001955status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001956 sp<CameraDeviceBase> device = mDevice;
1957 if (!device) {
1958 dprintf(out, " Device is detached.");
1959 return OK;
1960 }
1961 device->startWatchingTags(tags);
1962 return OK;
1963}
1964
1965status_t CameraDeviceClient::stopWatchingTags(int out) {
1966 sp<CameraDeviceBase> device = mDevice;
1967 if (!device) {
1968 dprintf(out, " Device is detached.");
1969 return OK;
1970 }
1971 device->stopWatchingTags();
1972 return OK;
1973}
1974
1975status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
1976 sp<CameraDeviceBase> device = mDevice;
1977 if (!device) {
1978 return OK;
1979 }
1980 device->dumpWatchedEventsToVector(out);
1981 return OK;
1982}
1983
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001984void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07001985 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001986 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001987 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001988
Emilian Peev538c90e2018-12-17 18:03:19 +00001989 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001990 {
1991 // Access to the composite stream map must be synchronized
1992 Mutex::Autolock l(mCompositeLock);
1993 // Composites can have multiple internal streams. Error notifications coming from such
1994 // internal streams may need to remain within camera service.
1995 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
1996 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
1997 resultExtras);
1998 }
Emilian Peev538c90e2018-12-17 18:03:19 +00001999 }
2000
2001 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002002 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002003 }
2004}
2005
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002006void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2007 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2008
2009 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002010 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002011 }
2012
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002013 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002014 mStreamingRequestId = REQUEST_ID_NONE;
2015}
2016
Shuzhen Wang316781a2020-08-18 18:11:01 -07002017void CameraDeviceClient::notifyIdle(
2018 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -07002019 std::pair<int32_t, int32_t> mostRequestedFpsRange,
Shuzhen Wang316781a2020-08-18 18:11:01 -07002020 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002021 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002022 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002023
2024 if (remoteCb != 0) {
2025 remoteCb->onDeviceIdle();
2026 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002027
2028 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2029 {
2030 Mutex::Autolock l(mCompositeLock);
2031 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2032 hardware::CameraStreamStats compositeStats;
2033 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2034 if (compositeStats.mWidth > 0) {
2035 fullStreamStats.push_back(compositeStats);
2036 }
2037 }
2038 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002039 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -07002040 mostRequestedFpsRange,
2041 fullStreamStats,
2042 mRunningSessionStats.mUserTag,
2043 mRunningSessionStats.mVideoStabilizationMode,
2044 mRunningSessionStats.mUsedUltraWide,
2045 mRunningSessionStats.mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002046}
2047
Jianing Weicb0652e2014-03-12 18:29:36 -07002048void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002049 nsecs_t timestamp) {
2050 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002051 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002052 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002053 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002054 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002055 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002056
Emilian Peev2f5d6012022-01-19 16:16:50 -08002057 // Access to the composite stream map must be synchronized
2058 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002059 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2060 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2061 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002062}
2063
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002064void CameraDeviceClient::notifyPrepared(int streamId) {
2065 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002066 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002067 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002068 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002069 remoteCb->onPrepared(streamId);
2070 }
2071}
2072
Shuzhen Wang9d066012016-09-30 11:30:20 -07002073void CameraDeviceClient::notifyRequestQueueEmpty() {
2074 // Thread safe. Don't bother locking.
2075 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2076 if (remoteCb != 0) {
2077 remoteCb->onRequestQueueEmpty();
2078 }
2079}
2080
Igor Murashkine7ee7632013-06-11 18:10:18 -07002081void CameraDeviceClient::detachDevice() {
2082 if (mDevice == 0) return;
2083
Shuzhen Wang316781a2020-08-18 18:11:01 -07002084 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002085 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002086
Emilian Peev7ee731f2022-02-08 14:55:52 -08002087 if (mFrameProcessor.get() != nullptr) {
2088 mFrameProcessor->removeListener(
2089 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2090 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2091 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002092 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002093 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002094 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002095 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002096
2097 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2098 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002099 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002100 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002101 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2102 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2103 }
2104
Igor Murashkine7ee7632013-06-11 18:10:18 -07002105 if ((code = mDevice->waitUntilDrained()) != OK) {
2106 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2107 code);
2108 }
2109 }
2110
Emilian Peev2f5d6012022-01-19 16:16:50 -08002111 {
2112 Mutex::Autolock l(mCompositeLock);
2113 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2114 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2115 if (ret != OK) {
2116 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2117 strerror(-ret), ret);
2118 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002119 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002120 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002121 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002122
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002123 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002124 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002125
2126 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002127 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002128}
2129
2130/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002131void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002132 ATRACE_CALL();
2133 ALOGV("%s", __FUNCTION__);
2134
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002135 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002136 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002137 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002138 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2139 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002140 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002141
Emilian Peev2f5d6012022-01-19 16:16:50 -08002142 // Access to the composite stream map must be synchronized
2143 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002144 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2145 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2146 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002147}
2148
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002149binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002150 if (mDisconnected) {
2151 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2152 "The camera device has been disconnected");
2153 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002154 status_t res = checkPid(checkLocation);
2155 return (res == OK) ? binder::Status::ok() :
2156 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2157 "Attempt to use camera from a different process than original client");
2158}
2159
Igor Murashkine7ee7632013-06-11 18:10:18 -07002160// TODO: move to Camera2ClientBase
2161bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2162
Austin Borger22c5c852024-03-08 13:31:36 -08002163 const int pid = getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002164 const int selfPid = getpid();
2165 camera_metadata_entry_t entry;
2166
2167 /**
2168 * Mixin default important security values
2169 * - android.led.transmit = defaulted ON
2170 */
2171 CameraMetadata staticInfo = mDevice->info();
2172 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2173 for(size_t i = 0; i < entry.count; ++i) {
2174 uint8_t led = entry.data.u8[i];
2175
2176 switch(led) {
2177 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2178 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2179 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2180 metadata.update(ANDROID_LED_TRANSMIT,
2181 &transmitDefault, 1);
2182 }
2183 break;
2184 }
2185 }
2186 }
2187
2188 // We can do anything!
2189 if (pid == selfPid) {
2190 return true;
2191 }
2192
2193 /**
2194 * Permission check special fields in the request
2195 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2196 */
2197 entry = metadata.find(ANDROID_LED_TRANSMIT);
2198 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2199 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002200 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002201 if (!checkCallingPermission(permissionString)) {
Austin Borger22c5c852024-03-08 13:31:36 -08002202 const int uid = getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002203 ALOGE("Permission Denial: "
2204 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2205 return false;
2206 }
2207 }
2208
2209 return true;
2210}
2211
Austin Borger1c1bee02023-06-01 16:51:35 -07002212const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002213 if (mDevice->getId() == cameraId) {
2214 return mDevice->info();
2215 }
2216 return mDevice->infoPhysical(cameraId);
2217}
2218
Austin Borger1c1bee02023-06-01 16:51:35 -07002219bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002220 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002221 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002222}
2223
2224bool CameraDeviceClient::isSensorPixelModeConsistent(
2225 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2226 // First we get the sensorPixelMode from the settings metadata.
2227 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2228 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2229 if (sensorPixelModeEntry.count != 0) {
2230 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2231 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2232 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2233 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2234 __FUNCTION__, sensorPixelMode);
2235 return false;
2236 }
2237 }
2238 // Check whether each stream has max resolution allowed.
2239 bool consistent = true;
2240 for (auto it : streamIdList) {
2241 auto const streamInfoIt = mStreamInfoMap.find(it);
2242 if (streamInfoIt == mStreamInfoMap.end()) {
2243 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2244 return false;
2245 }
2246 consistent =
2247 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2248 streamInfoIt->second.sensorPixelModesUsed.end();
2249 if (!consistent) {
2250 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2251 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2252 ALOGE("sensor pixel mode used list: %i", m);
2253 }
2254 break;
2255 }
2256 }
2257
2258 return consistent;
2259}
2260
Igor Murashkine7ee7632013-06-11 18:10:18 -07002261} // namespace android