blob: 8c30d54de7e0011fc28b1670baafa2e9414a2ffb [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,
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -070066 int sensorOrientation, int servicePid, int rotationOverride, bool sharedMode)
Austin Borger2e772b82024-10-11 16:09:57 -070067 : BasicClient(cameraService, IInterface::asBinder(remoteCallback),
68 attributionAndPermissionUtils, clientAttribution, callingPid, systemNativeClient,
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -070069 cameraId, cameraFacing, sensorOrientation, servicePid, rotationOverride,
70 sharedMode),
Austin Borger2e772b82024-10-11 16:09:57 -070071 mRemoteCallback(remoteCallback) {}
Igor Murashkine7ee7632013-06-11 18:10:18 -070072
73// Interface used by CameraService
74
Austin Borger2e772b82024-10-11 16:09:57 -070075CameraDeviceClient::CameraDeviceClient(
76 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080077 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070078 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger17e3ebe2024-02-14 15:02:11 -080079 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger2e772b82024-10-11 16:09:57 -070080 const AttributionSourceState& clientAttribution, int callingPid, bool systemNativeClient,
81 const std::string& cameraId, int cameraFacing, int sensorOrientation, int servicePid,
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -070082 bool overrideForPerfClass, int rotationOverride, const std::string& originalCameraId,
83 bool sharedMode)
Austin Borger2e772b82024-10-11 16:09:57 -070084 : Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper,
85 attributionAndPermissionUtils, clientAttribution, callingPid,
86 systemNativeClient, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -070087 sensorOrientation, servicePid, overrideForPerfClass, rotationOverride,
88 sharedMode),
Austin Borger2e772b82024-10-11 16:09:57 -070089 mInputStream(),
90 mStreamingRequestId(REQUEST_ID_NONE),
91 mRequestIdCounter(0),
92 mOverrideForPerfClass(overrideForPerfClass),
93 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070094 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -070095 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -070096}
97
Emilian Peevbd8c5032018-02-14 23:05:40 +000098status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -070099 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000100 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800101}
102
103template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700104status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
105 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700106 ATRACE_CALL();
107 status_t res;
108
Emilian Peevbd8c5032018-02-14 23:05:40 +0000109 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700110 if (res != OK) {
111 return res;
112 }
113
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700114 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700115 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
116 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700117 if (res != OK) {
118 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
119 __FUNCTION__, strerror(-res), res);
120 return res;
121 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700122
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800123 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
124 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800125 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700126 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700127
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800128 const CameraMetadata &deviceInfo = mDevice->info();
129 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000130 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
131 if (physicalKeysEntry.count > 0) {
132 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
133 physicalKeysEntry.data.i32,
134 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
135 }
136
Emilian Peev2295df72021-11-12 18:14:10 -0800137 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
138 mDynamicProfileMap.emplace(
139 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
140 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
141 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800142 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800143 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800144 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800145 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800146 if (entry.count > 0 || ((entry.count % 3) != 0)) {
147 int64_t standardBitmap =
148 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
149 for (size_t i = 0; i < entry.count; i += 3) {
150 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800151 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800152 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
153 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800154 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800155 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800156 }
157 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800158 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
159 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800160 }
161 }
Emilian Peevef715e22022-05-19 17:44:33 -0700162 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
163 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800164 } else {
165 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
166 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
167 }
168 }
169 }
170
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700171 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800172 // Cache physical camera ids corresponding to this device and also the high
173 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700174 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800175 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700176 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800177 }
178 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700179 if (supportsUltraHighResolutionCapture(physicalId)) {
180 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800181 }
182 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700183 return OK;
184}
185
186CameraDeviceClient::~CameraDeviceClient() {
187}
188
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800189binder::Status CameraDeviceClient::submitRequest(
190 const hardware::camera2::CaptureRequest& request,
191 bool streaming,
192 /*out*/
193 hardware::camera2::utils::SubmitInfo *submitInfo) {
194 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
195 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700196}
197
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800198binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000199 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000200 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800201 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
202
Emilian Peev2f5d6012022-01-19 16:16:50 -0800203 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800204 // Trying to submit request with surface that wasn't created
205 if (idx == NAME_NOT_FOUND) {
206 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
207 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700208 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800209 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
210 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000211 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
212 != NAME_NOT_FOUND) {
213 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
214 currentStreamId);
215 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800216 }
217
218 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
219 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220 outputStreamIds->push_back(streamSurfaceId.streamId());
221 }
222 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
223
224 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700225 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800226 streamSurfaceId.surfaceId());
227
Emilian Peevf873aa52018-01-26 14:58:28 +0000228 if (currentStreamId != nullptr) {
229 *currentStreamId = streamSurfaceId.streamId();
230 }
231
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800232 return binder::Status::ok();
233}
234
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800235static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
236 const Vector<int> &streamIdsForThisRequest) {
237 std::list<int> intersection;
238 for (auto &streamId : streamIdsForThisRequest) {
239 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
240 intersection.emplace_back(streamId);
241 }
242 }
243 return intersection;
244}
245
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800246binder::Status CameraDeviceClient::submitRequestList(
247 const std::vector<hardware::camera2::CaptureRequest>& requests,
248 bool streaming,
249 /*out*/
250 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700251 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700252 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700253
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800254 binder::Status res = binder::Status::ok();
255 status_t err;
256 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
257 return res;
258 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700259
260 Mutex::Autolock icl(mBinderSerializationLock);
261
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800262 if (!mDevice.get()) {
263 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
264 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700265
266 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800267 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700268 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800269 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700270 }
271
Emilian Peevaebbe412018-01-15 13:53:24 +0000272 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Ryan Prichard09a5c6e2024-06-27 23:42:58 -0700273 std::list<SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800274 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700275 uint32_t loopCounter = 0;
276
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800277 for (auto&& request: requests) {
278 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700279 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800280 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700281 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800282 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800283 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700284 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700285 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800286 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700287 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800288 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
289 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000290 } else if (request.mPhysicalCameraSettings.size() > 1) {
291 ALOGE("%s: Camera %s: reprocess requests not supported for "
292 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700293 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000294 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
295 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700296 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700297 }
298
Emilian Peevaebbe412018-01-15 13:53:24 +0000299 if (request.mPhysicalCameraSettings.empty()) {
300 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700301 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800302 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000303 "Request doesn't contain any settings");
304 }
305
306 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700307 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000308 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000309 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700310 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000311 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
312 "Invalid camera request settings");
313 }
314
Emilian Peevaebbe412018-01-15 13:53:24 +0000315 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800316 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700317 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800318 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
319 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700320 }
321
Jianing Wei90e59c92014-03-12 18:29:36 -0700322 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700323 * Write in the output stream IDs and map from stream ID to surface ID
324 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700325 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700326 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700327 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000328 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800329 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800330 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800331 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800332 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700333
Emilian Peevf873aa52018-01-26 14:58:28 +0000334 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800335 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000336 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800337 if (!res.isOk()) {
338 return res;
339 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000340
341 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
342 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700343 const std::string &requestedPhysicalId =
344 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
345 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800346 dynamicProfileBitmap |=
347 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000348 } else {
349 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
350 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700351 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800352 } else {
353 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
354 int streamId = request.mStreamIdxList.itemAt(i);
355 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700356
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800357 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
358 if (index < 0) {
359 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
360 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700361 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800362 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
363 "Request targets Surface that is not part of current capture session");
364 }
365
366 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
367 if ((size_t)surfaceIdx >= gbps.size()) {
368 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
369 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700370 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800371 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
372 "Request targets Surface has invalid surface index");
373 }
374
Emilian Peevf873aa52018-01-26 14:58:28 +0000375 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800376 if (!res.isOk()) {
377 return res;
378 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000379
Austin Borger1c1bee02023-06-01 16:51:35 -0700380 const std::string &requestedPhysicalId =
381 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
382 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800383 dynamicProfileBitmap |=
384 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
385 }
386 }
387
388 if (dynamicProfileBitmap !=
389 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
390 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
391 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
392 if ((dynamicProfileBitmap & i) == 0) {
393 continue;
394 }
395
396 const auto& it = mDynamicProfileMap.find(i);
397 if (it != mDynamicProfileMap.end()) {
398 if ((it->second == 0) ||
399 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
400 continue;
401 } else {
402 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
403 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700404 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800405 dynamicProfileBitmap);
406 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
407 "Request targets an unsupported dynamic range profile"
408 " combination");
409 }
410 } else {
411 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
412 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700413 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800414 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
415 "Request targets 10-bit Surface with unsupported dynamic range"
416 " profile");
417 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700418 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700419 }
420
Emilian Peevf873aa52018-01-26 14:58:28 +0000421 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
422 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000423 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000424 if (it.settings.isEmpty()) {
425 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700426 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000427 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
428 "Request settings are empty");
429 }
430
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800431 // Check whether the physical / logical stream has settings
432 // consistent with the sensor pixel mode(s) it was configured with.
433 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000434 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800435 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
436 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
437 outputStreamIds);
438 if (!request.mIsReprocess &&
439 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
440 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
441 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000442 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800443 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
444 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
445 "streams configured");
446 }
447 }
448
malikakash73125c62023-07-21 22:44:34 +0000449 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700450 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
451 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
452 mSupportedPhysicalRequestKeys.end();
453 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
454 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
455 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000456 if (physicalId != mDevice->getId()) {
457 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000458 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000459 if (found == requestedPhysicalIds.end()) {
460 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700461 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000462 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
463 "Invalid physical camera id");
464 }
Emilian Peev00420d22018-02-05 21:33:13 +0000465
466 if (!mSupportedPhysicalRequestKeys.empty()) {
467 // Filter out any unsupported physical request keys.
468 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
469 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
470 filteredParams.getAndLock());
471 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
472 filteredParams.unlock(meta);
473
474 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
475 camera_metadata_ro_entry entry = it.settings.find(keyIt);
476 if (entry.count > 0) {
477 filteredParams.update(entry);
478 }
479 }
480
malikakash73125c62023-07-21 22:44:34 +0000481 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700482 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000483 }
484 } else {
malikakash73125c62023-07-21 22:44:34 +0000485 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000486 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000487 }
488
489 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
490 // Callee logs
491 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
492 "Caller does not have permission to change restricted controls");
493 }
494
Emilian Peevaebbe412018-01-15 13:53:24 +0000495 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
496 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700497
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800498 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000499 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
500 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700501 }
502
Emilian Peevaebbe412018-01-15 13:53:24 +0000503 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
504 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700505 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800506 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700507 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800508 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700509
Emilian Peevaebbe412018-01-15 13:53:24 +0000510 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700511 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800512
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700513 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800514 if (!request.mUserTag.empty()) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700515 mRunningSessionStats.mUserTag = request.mUserTag;
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800516 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700517 camera_metadata_entry entry =
518 physicalSettingsList.begin()->metadata.find(
519 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
520 if (entry.count == 1) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700521 mRunningSessionStats.mVideoStabilizationMode = entry.data.u8[0];
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700522 }
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700523
Shuzhen Wang968b23f2024-09-09 09:56:16 -0700524 if (!mRunningSessionStats.mUsedUltraWide) {
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700525 entry = physicalSettingsList.begin()->metadata.find(
526 ANDROID_CONTROL_ZOOM_RATIO);
527 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700528 mRunningSessionStats.mUsedUltraWide = true;
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700529 }
530 }
Shuzhen Wang0fccf0b2024-09-09 10:11:09 -0700531 if (!mRunningSessionStats.mUsedSettingsOverrideZoom) {
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000532 entry = physicalSettingsList.begin()->metadata.find(
533 ANDROID_CONTROL_SETTINGS_OVERRIDE);
534 if (entry.count == 1 && entry.data.i32[0] ==
535 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700536 mRunningSessionStats.mUsedSettingsOverrideZoom = true;
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000537 }
538 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700539 }
540 mRequestIdCounter++;
541
542 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700543 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
544 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800545 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700546 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800547 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700548 mCameraIdStr.c_str(), strerror(-err), err);
549 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800550 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700551 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700552 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700553 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700554 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700555 }
556 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700557 err = mDevice->captureList(metadataRequestList, surfaceMapList,
558 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800559 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700560 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800561 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700562 mCameraIdStr.c_str(), strerror(-err), err);
563 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800564 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700565 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700566 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800567 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700568 }
569
Austin Borger1c1bee02023-06-01 16:51:35 -0700570 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700571 return res;
572}
573
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800574binder::Status CameraDeviceClient::cancelRequest(
575 int requestId,
576 /*out*/
577 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700578 ATRACE_CALL();
579 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
580
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800581 status_t err;
582 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700583
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800584 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700585
586 Mutex::Autolock icl(mBinderSerializationLock);
587
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800588 if (!mDevice.get()) {
589 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
590 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700591
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700592 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700593 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700594 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
595 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
596 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
597 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700598 }
599
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800600 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700601
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800602 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800603 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700604 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700605 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800606 } else {
607 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800608 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700609 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700610 }
611
612 return res;
613}
614
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800615binder::Status CameraDeviceClient::beginConfigure() {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700616 ATRACE_CALL();
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700617 if (!flags::camera_multi_client()) {
618 return binder::Status::ok();
619 }
620 if (!mDevice.get()) {
621 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
622 }
623 status_t res = mDevice->beginConfigure();
624 if (res != OK) {
625 std::string msg = fmt::sprintf("Camera %s: Error beginning stream configuration: %s (%d)",
626 mCameraIdStr.c_str(), strerror(-res), res);
627 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
628 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
629 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800630 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700631}
632
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100633binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700634 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800635 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700636 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700637 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
638 __FUNCTION__, mInputStream.configured ? 1 : 0,
639 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700640
Zhijun He0effd522016-03-04 10:22:27 -0800641 binder::Status res;
642 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
643
Emilian Peevcc0b7952020-01-07 13:54:47 -0800644 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700645 std::string msg = "Invalid offline stream ids";
646 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
647 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800648 }
649
Zhijun He0effd522016-03-04 10:22:27 -0800650 Mutex::Autolock icl(mBinderSerializationLock);
651
652 if (!mDevice.get()) {
653 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
654 }
655
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700656 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000657 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000658 if (!res.isOk()) {
659 return res;
660 }
661
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700662 if (flags::camera_multi_client() && mSharedMode) {
663 // For shared camera session, streams are already configured
664 // earlier, hence no need to do it here.
665 return res;
666 }
667
Emilian Peev35ae8262018-11-08 13:11:32 +0000668 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
669 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700670 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
671 mCameraIdStr.c_str());
672 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
673 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000674 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700675 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
676 mCameraIdStr.c_str(), strerror(-err), err);
677 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
678 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000679 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800680 offlineStreamIds->clear();
681 mDevice->getOfflineStreamIds(offlineStreamIds);
682
Emilian Peev2f5d6012022-01-19 16:16:50 -0800683 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000684 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
685 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800686 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700687 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
688 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
689 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
690 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000691 break;
692 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800693
694 // Composite streams can only support offline mode in case all individual internal
695 // streams are also supported.
696 std::vector<int> internalStreams;
697 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800698 offlineStreamIds->erase(
699 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800700 [&internalStreams] (int streamId) {
701 auto it = std::find(internalStreams.begin(), internalStreams.end(),
702 streamId);
703 if (it != internalStreams.end()) {
704 internalStreams.erase(it);
705 return true;
706 }
707
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800708 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800709 if (internalStreams.empty()) {
710 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
711 }
712 }
713
714 for (const auto& offlineStreamId : *offlineStreamIds) {
715 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000716 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700717
718 nsecs_t configureEnd = systemTime();
719 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700720 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700721 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000722 }
723
724 return res;
725}
726
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800727binder::Status CameraDeviceClient::isSessionConfigurationSupported(
728 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800729
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800730 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800731 binder::Status res;
732 status_t ret = OK;
733 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
734
735 Mutex::Autolock icl(mBinderSerializationLock);
736
737 if (!mDevice.get()) {
738 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
739 }
740
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800741 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700742 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
743 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
744 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800745 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700746
Emilian Peev35ae8262018-11-08 13:11:32 +0000747 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700748 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700749 sessionConfiguration, mOverrideForPerfClass, /*checkSessionParams*/false,
750 status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000751 switch (ret) {
752 case OK:
753 // Expected, do nothing.
754 break;
755 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700756 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000757 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700758 mCameraIdStr.c_str());
759 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
760 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000761 }
762
763 break;
764 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700765 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000766 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700767 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000768 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700769 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000770 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800771 }
772
773 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700774}
775
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800776binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700777 ATRACE_CALL();
778 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
779
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800780 binder::Status res;
781 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700782
783 Mutex::Autolock icl(mBinderSerializationLock);
784
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800785 if (!mDevice.get()) {
786 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
787 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700788
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700789 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700790 std::vector<sp<IBinder>> surfaces;
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700791 std::vector<size_t> removedSurfaceIds;
Zhijun He5d677d12016-05-29 16:52:39 -0700792 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000793 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700794
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700795 if (mInputStream.configured && mInputStream.id == streamId) {
796 isInput = true;
797 } else {
798 // Guard against trying to delete non-created streams
799 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700800 if (streamId == mStreamMap.valueAt(i).streamId()) {
801 surfaces.push_back(mStreamMap.keyAt(i));
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700802 if (flags::camera_multi_client() && mSharedMode) {
803 removedSurfaceIds.push_back(mStreamMap.valueAt(i).surfaceId());
804 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700805 }
806 }
807
808 // See if this stream is one of the deferred streams.
809 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
810 if (streamId == mDeferredStreams[i]) {
811 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700812 break;
813 }
814 }
815
Emilian Peev2f5d6012022-01-19 16:16:50 -0800816 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000817 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
818 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
819 compositeIndex = i;
820 break;
821 }
822 }
823
Shuzhen Wang0129d522016-10-30 22:43:41 -0700824 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700825 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
826 " stream created yet", mCameraIdStr.c_str(), streamId);
827 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
828 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700829 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700830 }
831
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700832
833 status_t err;
834 if (flags::camera_multi_client() && mSharedMode) {
835 err = mDevice->removeSharedSurfaces(streamId, removedSurfaceIds);
836 } else {
837 // Also returns BAD_VALUE if stream ID was not valid
838 err = mDevice->deleteStream(streamId);
839 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700840
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800841 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700842 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
843 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
844 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
845 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800846 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700847 if (isInput) {
848 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700849 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700850 for (auto& surface : surfaces) {
851 mStreamMap.removeItem(surface);
852 }
853
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800854 mConfiguredOutputs.removeItem(streamId);
855
Shuzhen Wang0129d522016-10-30 22:43:41 -0700856 if (dIndex != NAME_NOT_FOUND) {
857 mDeferredStreams.removeItemsAt(dIndex);
858 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000859
860 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800861 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000862 status_t ret;
863 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
864 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700865 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
866 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
867 err, streamId);
868 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
869 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000870 }
871 mCompositeStreamMap.removeItemsAt(compositeIndex);
872 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800873 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
874 auto &streamSet = mapIt.second;
875 if (streamSet.find(streamId) != streamSet.end()) {
876 streamSet.erase(streamId);
877 break;
878 }
879 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700880 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700881 }
882
883 return res;
884}
885
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800886binder::Status CameraDeviceClient::createStream(
887 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
888 /*out*/
889 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700890 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700891
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800892 binder::Status res;
893 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700894
895 Mutex::Autolock icl(mBinderSerializationLock);
896
Shuzhen Wang0709c282024-02-12 09:09:32 -0800897 if (!outputConfiguration.isComplete()) {
898 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
899 "OutputConfiguration isn't valid!");
900 }
901
Shuzhen Wang0129d522016-10-30 22:43:41 -0700902 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
903 outputConfiguration.getGraphicBufferProducers();
904 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800905 bool deferredConsumer = outputConfiguration.isDeferred();
906 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700907 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800908 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800909 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800910 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800911 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800912 int timestampBase = outputConfiguration.getTimestampBase();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700913 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000914 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700915
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700916 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800917 outputConfiguration.getSurfaceType(), /*isConfigurationComplete*/true);
Emilian Peev35ae8262018-11-08 13:11:32 +0000918 if (!res.isOk()) {
919 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700920 }
Zhijun He5d677d12016-05-29 16:52:39 -0700921
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800922 if (!mDevice.get()) {
923 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
924 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700925 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800926 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000927 if (!res.isOk()) {
928 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800929 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000930
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700931 std::vector<SurfaceHolder> surfaces;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700932 std::vector<sp<IBinder>> binders;
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700933 std::vector<OutputStreamInfo> streamInfos;
Zhijun He5d677d12016-05-29 16:52:39 -0700934 status_t err;
935
936 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700937 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800938 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700939 }
940
Shuzhen Wang758c2152017-01-10 18:26:18 -0800941 OutputStreamInfo streamInfo;
942 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800943 const std::vector<int32_t> &sensorPixelModesUsed =
944 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700945 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700946 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700947 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800948 ssize_t index = mStreamMap.indexOfKey(binder);
949 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700950 std::string msg = std::string("Camera ") + mCameraIdStr
951 + ": Surface already has a stream created for it (ID "
952 + std::to_string(index) + ")";
953 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
954 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700955 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700956
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700957 int mirrorMode = outputConfiguration.getMirrorMode(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800958 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700959 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800960 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800961 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800962 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800963
964 if (!res.isOk())
965 return res;
966
967 if (!isStreamInfoValid) {
968 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700969 }
970
Shuzhen Wang758c2152017-01-10 18:26:18 -0800971 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700972 surfaces.push_back({surface, mirrorMode});
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700973 if (flags::camera_multi_client() && mSharedMode) {
974 streamInfos.push_back(streamInfo);
975 }
Ruben Brunkbba75572014-11-20 17:29:50 -0800976 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700977
Zhijun He125684a2015-12-26 15:07:30 -0800978 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100979 std::vector<int> surfaceIds;
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700980 if (flags::camera_multi_client() && mSharedMode) {
981 err = mDevice->getSharedStreamId(outputConfiguration, &streamId);
982 if (err == OK) {
983 err = mDevice->addSharedSurfaces(streamId, streamInfos, surfaces, &surfaceIds);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800984 }
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700985 } else {
986 bool isDepthCompositeStream =
987 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0].mSurface);
988 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(
989 surfaces[0].mSurface);
990 bool isJpegRCompositeStream =
991 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0].mSurface) &&
992 !mDevice->isCompositeJpegRDisabled();
993 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
994 sp<CompositeStream> compositeStream;
995 if (isDepthCompositeStream) {
996 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
997 } else if (isHeicCompositeStream) {
998 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
999 } else {
1000 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
1001 }
1002 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
Emilian Peev538c90e2018-12-17 18:03:19 +00001003 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -07001004 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001005 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -07001006 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001007 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
1008 useReadoutTimestamp);
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07001009 if (err == OK) {
1010 Mutex::Autolock l(mCompositeLock);
1011 mCompositeStreamMap.add(
1012 IInterface::asBinder(surfaces[0].mSurface->getIGraphicBufferProducer()),
1013 compositeStream);
1014 }
1015 } else {
1016 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
1017 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
1018 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
1019 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
1020 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
1021 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
1022 streamInfo.timestampBase, streamInfo.colorSpace, useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001023 }
1024 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001025
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001026 if (err != OK) {
1027 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001028 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001029 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Henri Chataingbcb99452023-11-01 17:40:30 +00001030 static_cast<int>(streamInfo.dataSpace), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001031 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001032 int i = 0;
1033 for (auto& binder : binders) {
1034 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1035 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001036 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1037 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001038 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001039
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001040 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001041 mStreamInfoMap[streamId] = streamInfo;
1042
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001043 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001044 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001045 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001046 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001047
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001048 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001049 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001050 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001051 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001052 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001053 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001054 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001055 }
1056
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001057 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001058 }
1059
1060 return res;
1061}
1062
Zhijun He5d677d12016-05-29 16:52:39 -07001063binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1064 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001065 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001066 /*out*/
1067 int* newStreamId) {
1068 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001069 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001070 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001071 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001072 status_t err;
1073 binder::Status res;
1074
1075 if (!mDevice.get()) {
1076 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1077 }
Shuzhen Wang0709c282024-02-12 09:09:32 -08001078 if (!outputConfiguration.isComplete()) {
1079 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1080 "OutputConfiguration isn't valid!");
1081 }
Zhijun He5d677d12016-05-29 16:52:39 -07001082
1083 // Infer the surface info for deferred surface stream creation.
1084 width = outputConfiguration.getWidth();
1085 height = outputConfiguration.getHeight();
1086 surfaceType = outputConfiguration.getSurfaceType();
1087 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1088 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001089 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001090 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1091 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1092 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1093 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1094 }
1095 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001096 std::vector<SurfaceHolder> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001097 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001098 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1099 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001100 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1101 // Here, we override sensor pixel modes
1102 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1103 const std::vector<int32_t> &sensorPixelModesUsed =
1104 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001105 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001106 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001107 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001108 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1109 "sensor pixel modes used not valid for deferred stream");
1110 }
1111
Shuzhen Wang0129d522016-10-30 22:43:41 -07001112 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1113 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001114 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001115 &streamId, physicalCameraId,
1116 overriddenSensorPixelModesUsed,
1117 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001118 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001119 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001120 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001121 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001122 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001123
1124 if (err != OK) {
1125 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001126 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Henri Chataingbcb99452023-11-01 17:40:30 +00001127 mCameraIdStr.c_str(), width, height, format, static_cast<int>(dataSpace),
1128 strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001129 } else {
1130 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1131 // a separate list to track. Once the deferred surface is set, this id will be
1132 // relocated to mStreamMap.
1133 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001134 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001135 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001136 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001137 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001138 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001139 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001140 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001141
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001142 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001143 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001144 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001145
Zhijun He5d677d12016-05-29 16:52:39 -07001146 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001147 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001148 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001149 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001150 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001151 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001152 }
Zhijun He5d677d12016-05-29 16:52:39 -07001153 }
1154 return res;
1155}
1156
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001157binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001158 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001159 /*out*/
1160 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001161
1162 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001163 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1164 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001165
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001166 binder::Status res;
1167 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001168
1169 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001170
1171 if (!mDevice.get()) {
1172 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1173 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001174
1175 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001176 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1177 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1178 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1179 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001180 }
1181
1182 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001183 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001184 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001185 mInputStream.configured = true;
1186 mInputStream.width = width;
1187 mInputStream.height = height;
1188 mInputStream.format = format;
1189 mInputStream.id = streamId;
1190
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001191 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001192 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001193
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001194 *newStreamId = streamId;
1195 } else {
1196 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001197 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001198 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001199 }
1200
1201 return res;
1202}
1203
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001204binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001205
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001206 binder::Status res;
1207 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1208
1209 if (inputSurface == NULL) {
1210 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001211 }
1212
1213 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001214 if (!mDevice.get()) {
1215 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1216 }
Carlos Martinez Romero8e776102024-08-21 12:49:10 -07001217#if WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES
1218 sp<Surface> surface;
1219 status_t err = mDevice->getInputSurface(&surface);
1220 if (err != OK) {
1221 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1222 "Camera %s: Error getting input Surface: %s (%d)",
1223 mCameraIdStr.c_str(), strerror(-err), err);
1224 } else {
1225 inputSurface->name = toString16("CameraInput");
1226 inputSurface->graphicBufferProducer = surface->getIGraphicBufferProducer();
1227 }
1228#else
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001229 sp<IGraphicBufferProducer> producer;
1230 status_t err = mDevice->getInputBufferProducer(&producer);
1231 if (err != OK) {
1232 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001233 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001234 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001235 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001236 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001237 inputSurface->graphicBufferProducer = producer;
1238 }
Carlos Martinez Romero8e776102024-08-21 12:49:10 -07001239#endif
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001240 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001241}
1242
Emilian Peev40ead602017-09-26 15:46:36 +01001243binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1244 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1245 ATRACE_CALL();
1246
1247 binder::Status res;
1248 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1249
1250 Mutex::Autolock icl(mBinderSerializationLock);
1251
1252 if (!mDevice.get()) {
1253 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1254 }
Shuzhen Wang0709c282024-02-12 09:09:32 -08001255 if (!outputConfiguration.isComplete()) {
1256 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1257 "OutputConfiguration isn't valid!");
1258 }
Emilian Peev40ead602017-09-26 15:46:36 +01001259
1260 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1261 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001262 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001263
Emilian Peev40ead602017-09-26 15:46:36 +01001264 auto producerCount = bufferProducers.size();
1265 if (producerCount == 0) {
1266 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1267 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1268 "bufferProducers must not be empty");
1269 }
1270
1271 // The first output is the one associated with the output configuration.
1272 // It should always be present, valid and the corresponding stream id should match.
1273 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1274 ssize_t index = mStreamMap.indexOfKey(binder);
1275 if (index == NAME_NOT_FOUND) {
1276 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1277 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1278 "OutputConfiguration is invalid");
1279 }
1280 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1281 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1282 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1283 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1284 "Stream id is invalid");
1285 }
1286
1287 std::vector<size_t> removedSurfaceIds;
1288 std::vector<sp<IBinder>> removedOutputs;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001289 std::vector<SurfaceHolder> newOutputs;
Emilian Peev40ead602017-09-26 15:46:36 +01001290 std::vector<OutputStreamInfo> streamInfos;
1291 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1292 for (auto &it : bufferProducers) {
1293 newOutputsMap.add(IInterface::asBinder(it), it);
1294 }
1295
1296 for (size_t i = 0; i < mStreamMap.size(); i++) {
1297 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1298 if (idx == NAME_NOT_FOUND) {
1299 if (mStreamMap[i].streamId() == streamId) {
1300 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1301 removedOutputs.push_back(mStreamMap.keyAt(i));
1302 }
1303 } else {
1304 if (mStreamMap[i].streamId() != streamId) {
1305 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1306 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1307 "Target Surface is invalid");
1308 }
1309 newOutputsMap.removeItemsAt(idx);
1310 }
1311 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001312 const std::vector<int32_t> &sensorPixelModesUsed =
1313 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001314 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001315 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001316 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001317 int32_t colorSpace = outputConfiguration.getColorSpace();
Emilian Peev2295df72021-11-12 18:14:10 -08001318
Emilian Peev40ead602017-09-26 15:46:36 +01001319 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1320 OutputStreamInfo outInfo;
1321 sp<Surface> surface;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001322 int mirrorMode = outputConfiguration.getMirrorMode(newOutputsMap.valueAt(i));
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001323 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001324 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001325 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -08001326 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Emilian Peev40ead602017-09-26 15:46:36 +01001327 if (!res.isOk())
1328 return res;
1329
Emilian Peev40ead602017-09-26 15:46:36 +01001330 streamInfos.push_back(outInfo);
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001331 newOutputs.push_back({surface, mirrorMode});
Emilian Peev40ead602017-09-26 15:46:36 +01001332 }
1333
1334 //Trivial case no changes required
1335 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1336 return binder::Status::ok();
1337 }
1338
1339 KeyedVector<sp<Surface>, size_t> outputMap;
1340 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1341 &outputMap);
1342 if (ret != OK) {
1343 switch (ret) {
1344 case NAME_NOT_FOUND:
1345 case BAD_VALUE:
1346 case -EBUSY:
1347 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1348 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001349 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001350 break;
1351 default:
1352 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1353 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001354 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001355 break;
1356 }
1357 } else {
1358 for (const auto &it : removedOutputs) {
1359 mStreamMap.removeItem(it);
1360 }
1361
1362 for (size_t i = 0; i < outputMap.size(); i++) {
1363 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1364 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1365 }
1366
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001367 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1368
Emilian Peev40ead602017-09-26 15:46:36 +01001369 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001370 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001371 }
1372
1373 return res;
1374}
1375
Igor Murashkine7ee7632013-06-11 18:10:18 -07001376// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001377binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1378 /*out*/
1379 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001380{
1381 ATRACE_CALL();
1382 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1383
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001384 binder::Status res;
1385 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001386
1387 Mutex::Autolock icl(mBinderSerializationLock);
1388
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001389 if (!mDevice.get()) {
1390 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1391 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001392
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001393 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001394 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001395 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1396 mCameraIdStr, templateId, &tempId);
1397 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001398
1399 CameraMetadata metadata;
1400 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001401 request != NULL) {
1402
1403 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001404 } else if (err == BAD_VALUE) {
1405 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001406 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001407 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001408
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001409 } else {
1410 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001411 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001412 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001413 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001414 return res;
1415}
1416
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001417binder::Status CameraDeviceClient::getCameraInfo(
1418 /*out*/
1419 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001420{
1421 ATRACE_CALL();
1422 ALOGV("%s", __FUNCTION__);
1423
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001424 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001425
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001426 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001427
1428 Mutex::Autolock icl(mBinderSerializationLock);
1429
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001430 if (!mDevice.get()) {
1431 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1432 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001433
Igor Murashkin099b4572013-07-12 17:52:16 -07001434 if (info != NULL) {
1435 *info = mDevice->info(); // static camera metadata
1436 // TODO: merge with device-specific camera metadata
1437 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001438
1439 return res;
1440}
1441
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001442binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001443{
1444 ATRACE_CALL();
1445 ALOGV("%s", __FUNCTION__);
1446
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001447 binder::Status res;
1448 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001449
1450 Mutex::Autolock icl(mBinderSerializationLock);
1451
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001452 if (!mDevice.get()) {
1453 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1454 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001455
1456 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001457 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001458 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001459 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001460 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001461 mCameraIdStr.c_str());
1462 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1463 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001464 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001465 status_t err = mDevice->waitUntilDrained();
1466 if (err != OK) {
1467 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001468 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001469 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001470 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001471 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001472 return res;
1473}
1474
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001475binder::Status CameraDeviceClient::flush(
1476 /*out*/
1477 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001478 ATRACE_CALL();
1479 ALOGV("%s", __FUNCTION__);
1480
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001481 binder::Status res;
1482 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001483
1484 Mutex::Autolock icl(mBinderSerializationLock);
1485
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001486 if (!mDevice.get()) {
1487 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1488 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001489
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001490 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001491 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001492 status_t err = mDevice->flush(lastFrameNumber);
1493 if (err != OK) {
1494 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001495 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1496 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001497 }
1498 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001499}
1500
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001501binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001502 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001503 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001504
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001505 binder::Status res;
1506 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001507
1508 Mutex::Autolock icl(mBinderSerializationLock);
1509
1510 // Guard against trying to prepare non-created streams
1511 ssize_t index = NAME_NOT_FOUND;
1512 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001513 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001514 index = i;
1515 break;
1516 }
1517 }
1518
1519 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001520 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1521 "with that ID exists", mCameraIdStr.c_str(), streamId);
1522 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1523 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001524 }
1525
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001526 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1527 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001528 status_t err = mDevice->prepare(streamId);
1529 if (err == BAD_VALUE) {
1530 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001531 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001532 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001533 } else if (err != OK) {
1534 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001535 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001536 strerror(-err), err);
1537 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001538 return res;
1539}
1540
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001541binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001542 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001543 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001544
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001545 binder::Status res;
1546 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001547
1548 Mutex::Autolock icl(mBinderSerializationLock);
1549
1550 // Guard against trying to prepare non-created streams
1551 ssize_t index = NAME_NOT_FOUND;
1552 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001553 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001554 index = i;
1555 break;
1556 }
1557 }
1558
1559 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001560 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1561 "with that ID exists", mCameraIdStr.c_str(), streamId);
1562 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1563 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001564 }
1565
1566 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001567 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1568 mCameraIdStr.c_str(), maxCount);
1569 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1570 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001571 }
1572
1573 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1574 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001575 status_t err = mDevice->prepare(maxCount, streamId);
1576 if (err == BAD_VALUE) {
1577 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001578 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001579 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001580 } else if (err != OK) {
1581 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001582 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001583 strerror(-err), err);
1584 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001585
1586 return res;
1587}
1588
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001589binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001590 ATRACE_CALL();
1591 ALOGV("%s", __FUNCTION__);
1592
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001593 binder::Status res;
1594 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001595
1596 Mutex::Autolock icl(mBinderSerializationLock);
1597
1598 // Guard against trying to prepare non-created streams
1599 ssize_t index = NAME_NOT_FOUND;
1600 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001601 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001602 index = i;
1603 break;
1604 }
1605 }
1606
1607 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001608 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1609 "with that ID exists", mCameraIdStr.c_str(), streamId);
1610 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1611 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001612 }
1613
1614 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1615 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001616 status_t err = mDevice->tearDown(streamId);
1617 if (err == BAD_VALUE) {
1618 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001619 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001620 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001621 } else if (err != OK) {
1622 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001623 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001624 strerror(-err), err);
1625 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001626
1627 return res;
1628}
1629
Shuzhen Wang758c2152017-01-10 18:26:18 -08001630binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001631 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1632 ATRACE_CALL();
1633
1634 binder::Status res;
1635 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1636
1637 Mutex::Autolock icl(mBinderSerializationLock);
1638
Shuzhen Wang0709c282024-02-12 09:09:32 -08001639 if (!outputConfiguration.isComplete()) {
1640 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1641 "OutputConfiguration isn't valid!");
1642 }
1643
Shuzhen Wang0129d522016-10-30 22:43:41 -07001644 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1645 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001646 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001647
Shuzhen Wang0129d522016-10-30 22:43:41 -07001648 if (bufferProducers.size() == 0) {
1649 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001650 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1651 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001652
Shuzhen Wang758c2152017-01-10 18:26:18 -08001653 // streamId should be in mStreamMap if this stream already has a surface attached
1654 // to it. Otherwise, it should be in mDeferredStreams.
1655 bool streamIdConfigured = false;
1656 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1657 for (size_t i = 0; i < mStreamMap.size(); i++) {
1658 if (mStreamMap.valueAt(i).streamId() == streamId) {
1659 streamIdConfigured = true;
1660 break;
1661 }
Zhijun He5d677d12016-05-29 16:52:39 -07001662 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001663 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1664 if (streamId == mDeferredStreams[i]) {
1665 deferredStreamIndex = i;
1666 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001667 }
1668
Shuzhen Wang758c2152017-01-10 18:26:18 -08001669 }
1670 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001671 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1672 "(ID %d)", mCameraIdStr.c_str(), streamId);
1673 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1674 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001675 }
1676
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001677 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001678 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1679 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1680 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1681 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001682 }
1683
Zhijun He5d677d12016-05-29 16:52:39 -07001684 if (!mDevice.get()) {
1685 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1686 }
1687
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001688 std::vector<SurfaceHolder> consumerSurfaceHolders;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001689 const std::vector<int32_t> &sensorPixelModesUsed =
1690 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001691 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001692 int32_t colorSpace = outputConfiguration.getColorSpace();
1693 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001694 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001695 for (auto& bufferProducer : bufferProducers) {
1696 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001697 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1698 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001699 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001700 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001701 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001702 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001703
1704 sp<Surface> surface;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001705 int mirrorMode = outputConfiguration.getMirrorMode(bufferProducer);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001706 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001707 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001708 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -08001709 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001710
1711 if (!res.isOk())
1712 return res;
1713
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001714 consumerSurfaceHolders.push_back({surface, mirrorMode});
Zhijun He5d677d12016-05-29 16:52:39 -07001715 }
1716
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001717 // Gracefully handle case where finalizeOutputConfigurations is called
1718 // without any new surface.
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001719 if (consumerSurfaceHolders.size() == 0) {
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001720 mStreamInfoMap[streamId].finalized = true;
1721 return res;
1722 }
1723
Zhijun He5d677d12016-05-29 16:52:39 -07001724 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001725 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001726 std::vector<int> consumerSurfaceIds;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001727 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaceHolders, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001728 if (err == OK) {
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001729 for (size_t i = 0; i < consumerSurfaceHolders.size(); i++) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001730 sp<IBinder> binder = IInterface::asBinder(
Shuzhen Wang38df0ca2024-10-09 11:33:44 -07001731 consumerSurfaceHolders[i].mSurface->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001732 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001733 binder.get(), streamId, consumerSurfaceIds[i]);
1734 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1735 }
1736 if (deferredStreamIndex != NAME_NOT_FOUND) {
1737 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001738 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001739 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001740 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001741 } else if (err == NO_INIT) {
1742 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001743 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001744 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001745 } else {
1746 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001747 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001748 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001749 }
1750
1751 return res;
1752}
1753
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001754binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001755 ATRACE_CALL();
1756 binder::Status res;
1757 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1758
1759 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001760 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1761 mCameraIdStr.c_str(), mode);
1762 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1763 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001764 }
1765
1766 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001767 BasicClient::setAudioRestriction(mode);
1768 return binder::Status::ok();
1769}
1770
1771binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1772 ATRACE_CALL();
1773 binder::Status res;
1774 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1775 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001776 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001777 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001778 }
1779 return binder::Status::ok();
1780}
1781
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07001782binder::Status CameraDeviceClient::isPrimaryClient(/*out*/bool* isPrimary) {
1783 ATRACE_CALL();
1784 binder::Status res = binder::Status::ok();
1785 if (!flags::camera_multi_client()) {
1786 return res;
1787 }
1788 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1789 if (isPrimary != nullptr) {
1790 status_t ret = BasicClient::isPrimaryClient(isPrimary);
1791 return binder::Status::fromStatusT(ret);
1792 }
1793 return res;
1794}
1795
Ravneetaeb20dc2022-03-30 05:33:03 +00001796status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1797 return mDevice->setCameraServiceWatchdog(enabled);
1798}
1799
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001800status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001801 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1802
1803 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001804 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001805}
1806
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001807status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1808 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1809
1810 return mDevice->setAutoframingAutoBehavior(
1811 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1812}
1813
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001814bool CameraDeviceClient::supportsCameraMute() {
1815 return mDevice->supportsCameraMute();
1816}
1817
1818status_t CameraDeviceClient::setCameraMute(bool enabled) {
1819 return mDevice->setCameraMute(enabled);
1820}
1821
Shuzhen Wang16610a62022-12-15 22:38:07 -08001822void CameraDeviceClient::setStreamUseCaseOverrides(
1823 const std::vector<int64_t>& useCaseOverrides) {
1824 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1825}
1826
1827void CameraDeviceClient::clearStreamUseCaseOverrides() {
1828 mDevice->clearStreamUseCaseOverrides();
1829}
1830
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001831bool CameraDeviceClient::supportsZoomOverride() {
1832 return mDevice->supportsZoomOverride();
1833}
1834
1835status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1836 return mDevice->setZoomOverride(zoomOverride);
1837}
1838
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001839binder::Status CameraDeviceClient::switchToOffline(
1840 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001841 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001842 /*out*/
1843 sp<hardware::camera2::ICameraOfflineSession>* session) {
1844 ATRACE_CALL();
1845
1846 binder::Status res;
1847 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1848
1849 Mutex::Autolock icl(mBinderSerializationLock);
1850
1851 if (!mDevice.get()) {
1852 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1853 }
1854
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001855 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001856 std::string msg = "Offline surfaces must not be empty";
1857 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1858 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001859 }
1860
1861 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001862 std::string msg = "Invalid offline session";
1863 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1864 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001865 }
1866
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001867 std::vector<int32_t> offlineStreamIds;
1868 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001869 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001870 for (const auto& streamId : offlineOutputIds) {
1871 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001872 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001873 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001874 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001875 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1876 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001877 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001878
1879 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001880 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001881 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001882 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1883 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001884 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001885
Emilian Peev2f5d6012022-01-19 16:16:50 -08001886 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001887 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001888 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001889 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001890 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001891 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001892 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001893 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001894 if (isCompositeStream) {
1895 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1896 if (compositeIdx == NAME_NOT_FOUND) {
1897 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1898 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1899 "Unknown composite stream");
1900 }
1901
1902 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1903 &offlineStreamIds);
1904 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1905 mCompositeStreamMap.valueAt(compositeIdx));
1906 break;
1907 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001908 }
1909
Emilian Peev4697b642019-11-19 17:11:14 -08001910 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001911 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001912 }
1913 }
1914
1915 sp<CameraOfflineSessionBase> offlineSession;
1916 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1917 if (ret != OK) {
1918 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1919 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001920 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001921 }
1922
Emilian Peevcc0b7952020-01-07 13:54:47 -08001923 sp<CameraOfflineSessionClient> offlineClient;
1924 if (offlineSession.get() != nullptr) {
Austin Borger2e772b82024-10-11 16:09:57 -07001925 offlineClient = new CameraOfflineSessionClient(
1926 sCameraService, offlineSession, offlineCompositeStreamMap, cameraCb,
1927 mAttributionAndPermissionUtils, mClientAttribution, mCallingPid, mCameraIdStr,
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07001928 mCameraFacing, mOrientation, mServicePid, /*sharedMode*/false);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001929 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1930 }
1931
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001932 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001933 // A successful offline session switch must reset the current camera client
1934 // and release any resources occupied by previously configured streams.
1935 mStreamMap.clear();
1936 mConfiguredOutputs.clear();
1937 mDeferredStreams.clear();
1938 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001939 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001940 mCompositeStreamMap.clear();
1941 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001942 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001943 // In case we failed to register the offline client, ensure that it still initialized
1944 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001945 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001946
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001947 switch(ret) {
1948 case BAD_VALUE:
1949 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1950 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1951 case TIMED_OUT:
1952 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1953 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1954 default:
1955 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1956 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1957 strerror(-ret), ret);
1958 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001959 }
1960
1961 *session = offlineClient;
1962
1963 return binder::Status::ok();
1964}
1965
Igor Murashkine7ee7632013-06-11 18:10:18 -07001966status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001967 return BasicClient::dump(fd, args);
1968}
1969
1970status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001971 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001972 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001973 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001974 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Austin Borger2e772b82024-10-11 16:09:57 -07001975 dprintf(fd, " Current client UID %u\n", getClientUid());
Igor Murashkine7ee7632013-06-11 18:10:18 -07001976
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001977 dprintf(fd, " State:\n");
1978 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001979 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001980 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001981 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001982 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001983 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001984 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001985 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001986 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001987 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001988 mStreamMap.valueAt(i).streamId(),
1989 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001990 }
Zhijun He5d677d12016-05-29 16:52:39 -07001991 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001992 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001993 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001994 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001995 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001996 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001997 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001998 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001999 // TODO: print dynamic/request section from most recent requests
2000 mFrameProcessor->dump(fd, args);
2001
2002 return dumpDevice(fd, args);
2003}
2004
Austin Borger1c1bee02023-06-01 16:51:35 -07002005status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07002006 sp<CameraDeviceBase> device = mDevice;
2007 if (!device) {
2008 dprintf(out, " Device is detached.");
2009 return OK;
2010 }
2011 device->startWatchingTags(tags);
2012 return OK;
2013}
2014
2015status_t CameraDeviceClient::stopWatchingTags(int out) {
2016 sp<CameraDeviceBase> device = mDevice;
2017 if (!device) {
2018 dprintf(out, " Device is detached.");
2019 return OK;
2020 }
2021 device->stopWatchingTags();
2022 return OK;
2023}
2024
2025status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2026 sp<CameraDeviceBase> device = mDevice;
2027 if (!device) {
2028 return OK;
2029 }
2030 device->dumpWatchedEventsToVector(out);
2031 return OK;
2032}
2033
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002034void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002035 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002036 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002037 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002038
Emilian Peev538c90e2018-12-17 18:03:19 +00002039 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002040 {
2041 // Access to the composite stream map must be synchronized
2042 Mutex::Autolock l(mCompositeLock);
2043 // Composites can have multiple internal streams. Error notifications coming from such
2044 // internal streams may need to remain within camera service.
2045 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2046 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2047 resultExtras);
2048 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002049 }
2050
2051 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002052 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002053 }
2054}
2055
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002056void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2057 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2058
2059 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002060 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002061 }
2062
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002063 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002064 mStreamingRequestId = REQUEST_ID_NONE;
2065}
2066
Shuzhen Wang316781a2020-08-18 18:11:01 -07002067void CameraDeviceClient::notifyIdle(
2068 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -07002069 std::pair<int32_t, int32_t> mostRequestedFpsRange,
Shuzhen Wang316781a2020-08-18 18:11:01 -07002070 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002071 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002072 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002073
2074 if (remoteCb != 0) {
2075 remoteCb->onDeviceIdle();
2076 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002077
2078 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2079 {
2080 Mutex::Autolock l(mCompositeLock);
2081 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2082 hardware::CameraStreamStats compositeStats;
2083 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2084 if (compositeStats.mWidth > 0) {
2085 fullStreamStats.push_back(compositeStats);
2086 }
2087 }
2088 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002089 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -07002090 mostRequestedFpsRange,
2091 fullStreamStats,
2092 mRunningSessionStats.mUserTag,
2093 mRunningSessionStats.mVideoStabilizationMode,
2094 mRunningSessionStats.mUsedUltraWide,
2095 mRunningSessionStats.mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002096}
2097
Jianing Weicb0652e2014-03-12 18:29:36 -07002098void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002099 nsecs_t timestamp) {
2100 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002101 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002102 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002103 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002104 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002105 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002106
Emilian Peev2f5d6012022-01-19 16:16:50 -08002107 // Access to the composite stream map must be synchronized
2108 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002109 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2110 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2111 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002112}
2113
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002114void CameraDeviceClient::notifyPrepared(int streamId) {
2115 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002116 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002117 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002118 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002119 remoteCb->onPrepared(streamId);
2120 }
2121}
2122
Shuzhen Wang9d066012016-09-30 11:30:20 -07002123void CameraDeviceClient::notifyRequestQueueEmpty() {
2124 // Thread safe. Don't bother locking.
2125 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2126 if (remoteCb != 0) {
2127 remoteCb->onRequestQueueEmpty();
2128 }
2129}
2130
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07002131void CameraDeviceClient::notifyClientSharedAccessPriorityChanged(bool primaryClient) {
2132 // Thread safe. Don't bother locking.
2133 if (!flags::camera_multi_client()) {
2134 return;
2135 }
2136 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2137 if (remoteCb != 0) {
2138 remoteCb->onClientSharedAccessPriorityChanged(primaryClient);
2139 }
2140}
2141
Igor Murashkine7ee7632013-06-11 18:10:18 -07002142void CameraDeviceClient::detachDevice() {
2143 if (mDevice == 0) return;
2144
Shuzhen Wang316781a2020-08-18 18:11:01 -07002145 nsecs_t startTime = systemTime();
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07002146 if (!flags::camera_multi_client() || sCameraService->isOnlyClient(this)){
2147 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002148
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07002149 if (mFrameProcessor.get() != nullptr) {
2150 mFrameProcessor->removeListener(
2151 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2152 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2153 mFrameProcessor->requestExit();
2154 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
2155 mFrameProcessor->join();
2156 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002157 }
2158
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07002159 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2160 {
2161 int64_t lastFrameNumber;
2162 status_t code;
2163 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2164 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2165 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002166
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07002167 if ((code = mDevice->waitUntilDrained()) != OK) {
2168 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2169 code);
Emilian Peev2f5d6012022-01-19 16:16:50 -08002170 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002171 }
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -07002172
2173 {
2174 Mutex::Autolock l(mCompositeLock);
2175 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2176 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2177 if (ret != OK) {
2178 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2179 strerror(-ret), ret);
2180 }
2181 }
2182 mCompositeStreamMap.clear();
2183 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002184 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002185
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002186 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002187 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002188
2189 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002190 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002191}
2192
2193/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002194void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002195 ATRACE_CALL();
2196 ALOGV("%s", __FUNCTION__);
2197
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002198 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002199 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002200 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002201 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2202 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002203 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002204
Emilian Peev2f5d6012022-01-19 16:16:50 -08002205 // Access to the composite stream map must be synchronized
2206 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002207 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2208 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2209 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002210}
2211
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002212binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002213 if (mDisconnected) {
2214 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2215 "The camera device has been disconnected");
2216 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002217 status_t res = checkPid(checkLocation);
2218 return (res == OK) ? binder::Status::ok() :
2219 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2220 "Attempt to use camera from a different process than original client");
2221}
2222
Igor Murashkine7ee7632013-06-11 18:10:18 -07002223// TODO: move to Camera2ClientBase
2224bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2225
Austin Borger22c5c852024-03-08 13:31:36 -08002226 const int pid = getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002227 const int selfPid = getpid();
2228 camera_metadata_entry_t entry;
2229
2230 /**
2231 * Mixin default important security values
2232 * - android.led.transmit = defaulted ON
2233 */
2234 CameraMetadata staticInfo = mDevice->info();
2235 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2236 for(size_t i = 0; i < entry.count; ++i) {
2237 uint8_t led = entry.data.u8[i];
2238
2239 switch(led) {
2240 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2241 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2242 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2243 metadata.update(ANDROID_LED_TRANSMIT,
2244 &transmitDefault, 1);
2245 }
2246 break;
2247 }
2248 }
2249 }
2250
2251 // We can do anything!
2252 if (pid == selfPid) {
2253 return true;
2254 }
2255
2256 /**
2257 * Permission check special fields in the request
2258 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2259 */
2260 entry = metadata.find(ANDROID_LED_TRANSMIT);
2261 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2262 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002263 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002264 if (!checkCallingPermission(permissionString)) {
Austin Borger22c5c852024-03-08 13:31:36 -08002265 const int uid = getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002266 ALOGE("Permission Denial: "
2267 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2268 return false;
2269 }
2270 }
2271
2272 return true;
2273}
2274
Austin Borger1c1bee02023-06-01 16:51:35 -07002275const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002276 if (mDevice->getId() == cameraId) {
2277 return mDevice->info();
2278 }
2279 return mDevice->infoPhysical(cameraId);
2280}
2281
Austin Borger1c1bee02023-06-01 16:51:35 -07002282bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002283 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002284 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002285}
2286
2287bool CameraDeviceClient::isSensorPixelModeConsistent(
2288 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2289 // First we get the sensorPixelMode from the settings metadata.
2290 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2291 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2292 if (sensorPixelModeEntry.count != 0) {
2293 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2294 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2295 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2296 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2297 __FUNCTION__, sensorPixelMode);
2298 return false;
2299 }
2300 }
2301 // Check whether each stream has max resolution allowed.
2302 bool consistent = true;
2303 for (auto it : streamIdList) {
2304 auto const streamInfoIt = mStreamInfoMap.find(it);
2305 if (streamInfoIt == mStreamInfoMap.end()) {
2306 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2307 return false;
2308 }
2309 consistent =
2310 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2311 streamInfoIt->second.sensorPixelModesUsed.end();
2312 if (!consistent) {
2313 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2314 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2315 ALOGE("sensor pixel mode used list: %i", m);
2316 }
2317 break;
2318 }
2319 }
2320
2321 return consistent;
2322}
2323
Igor Murashkine7ee7632013-06-11 18:10:18 -07002324} // namespace android