blob: a55c23b938cf60ead37a33524a0fc2db2e5e0348 [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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 Talvala7b82efe2013-07-25 17:12:35 -070021#include <cutils/properties.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070022#include <utils/Log.h>
23#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070024#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070025#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070026#include <camera/CameraUtils.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070027
28#include "common/CameraDeviceBase.h"
29#include "api2/CameraDeviceClient.h"
30
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080031// Convenience methods for constructing binder::Status objects for error returns
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070032
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080033#define STATUS_ERROR(errorCode, errorString) \
34 binder::Status::fromServiceSpecificError(errorCode, \
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -080035 String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString))
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080036
37#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
38 binder::Status::fromServiceSpecificError(errorCode, \
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -080039 String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, \
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080040 __VA_ARGS__))
Igor Murashkine7ee7632013-06-11 18:10:18 -070041
42namespace android {
43using namespace camera2;
44
45CameraDeviceClientBase::CameraDeviceClientBase(
46 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080047 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Igor Murashkine7ee7632013-06-11 18:10:18 -070048 const String16& clientPackageName,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080049 const String8& cameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070050 int cameraFacing,
51 int clientPid,
52 uid_t clientUid,
53 int servicePid) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080054 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080055 IInterface::asBinder(remoteCallback),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080056 clientPackageName,
57 cameraId,
58 cameraFacing,
59 clientPid,
60 clientUid,
61 servicePid),
Igor Murashkine7ee7632013-06-11 18:10:18 -070062 mRemoteCallback(remoteCallback) {
63}
Igor Murashkine7ee7632013-06-11 18:10:18 -070064
65// Interface used by CameraService
66
67CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080068 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
69 const String16& clientPackageName,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080070 const String8& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080071 int cameraFacing,
72 int clientPid,
73 uid_t clientUid,
74 int servicePid) :
Igor Murashkine7ee7632013-06-11 18:10:18 -070075 Camera2ClientBase(cameraService, remoteCallback, clientPackageName,
76 cameraId, cameraFacing, clientPid, clientUid, servicePid),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070077 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -070078 mStreamingRequestId(REQUEST_ID_NONE),
Igor Murashkine7ee7632013-06-11 18:10:18 -070079 mRequestIdCounter(0) {
80
81 ATRACE_CALL();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080082 ALOGI("CameraDeviceClient %s: Opened", cameraId.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -070083}
84
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080085status_t CameraDeviceClient::initialize(CameraModule *module) {
86 return initializeImpl(module);
87}
88
89status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager) {
90 return initializeImpl(manager);
91}
92
93template<typename TProviderPtr>
94status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070095 ATRACE_CALL();
96 status_t res;
97
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080098 res = Camera2ClientBase::initialize(providerPtr);
Igor Murashkine7ee7632013-06-11 18:10:18 -070099 if (res != OK) {
100 return res;
101 }
102
103 String8 threadName;
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700104 mFrameProcessor = new FrameProcessorBase(mDevice);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800105 threadName = String8::format("CDU-%s-FrameProc", mCameraIdStr.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700106 mFrameProcessor->run(threadName.string());
107
108 mFrameProcessor->registerListener(FRAME_PROCESSOR_LISTENER_MIN_ID,
109 FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800110 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700111 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700112
113 return OK;
114}
115
116CameraDeviceClient::~CameraDeviceClient() {
117}
118
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800119binder::Status CameraDeviceClient::submitRequest(
120 const hardware::camera2::CaptureRequest& request,
121 bool streaming,
122 /*out*/
123 hardware::camera2::utils::SubmitInfo *submitInfo) {
124 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
125 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700126}
127
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800128binder::Status CameraDeviceClient::submitRequestList(
129 const std::vector<hardware::camera2::CaptureRequest>& requests,
130 bool streaming,
131 /*out*/
132 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700133 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700134 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700135
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800136 binder::Status res = binder::Status::ok();
137 status_t err;
138 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
139 return res;
140 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700141
142 Mutex::Autolock icl(mBinderSerializationLock);
143
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800144 if (!mDevice.get()) {
145 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
146 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700147
148 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800149 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
150 __FUNCTION__, mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800151 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700152 }
153
154 List<const CameraMetadata> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700155 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800156 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700157 uint32_t loopCounter = 0;
158
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800159 for (auto&& request: requests) {
160 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700161 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800162 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
163 mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800164 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800165 "No input configured for camera %s but request is for reprocessing",
166 mCameraIdStr.string());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700167 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800168 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
169 mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800170 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
171 "Repeating reprocess requests not supported");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700172 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700173 }
174
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800175 CameraMetadata metadata(request.mMetadata);
Jianing Wei90e59c92014-03-12 18:29:36 -0700176 if (metadata.isEmpty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800177 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
178 __FUNCTION__, mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800179 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
180 "Request settings are empty");
181 } else if (request.mSurfaceList.isEmpty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800182 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
183 "Rejecting request.", __FUNCTION__, mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800184 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
185 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700186 }
187
188 if (!enforceRequestPermissions(metadata)) {
189 // Callee logs
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800190 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
191 "Caller does not have permission to change restricted controls");
Jianing Wei90e59c92014-03-12 18:29:36 -0700192 }
193
194 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700195 * Write in the output stream IDs and map from stream ID to surface ID
196 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700197 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700198 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700199 Vector<int32_t> outputStreamIds;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800200 for (sp<Surface> surface : request.mSurfaceList) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700201 if (surface == 0) continue;
202
203 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Marco Nelissenf8880202014-11-14 07:58:25 -0800204 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
Jianing Wei90e59c92014-03-12 18:29:36 -0700205
206 // Trying to submit request with surface that wasn't created
207 if (idx == NAME_NOT_FOUND) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800208 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800209 " we have not called createStream on",
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800210 __FUNCTION__, mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800211 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
212 "Request targets Surface that is not part of current capture session");
Jianing Wei90e59c92014-03-12 18:29:36 -0700213 }
214
Shuzhen Wang0129d522016-10-30 22:43:41 -0700215 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
216 if (surfaceMap.find(streamSurfaceId.streamId()) == surfaceMap.end()) {
217 surfaceMap[streamSurfaceId.streamId()] = std::vector<size_t>();
218 outputStreamIds.push_back(streamSurfaceId.streamId());
219 }
220 surfaceMap[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
221
222 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
223 __FUNCTION__, mCameraIdStr.string(), streamSurfaceId.streamId(),
224 streamSurfaceId.surfaceId());
Jianing Wei90e59c92014-03-12 18:29:36 -0700225 }
226
227 metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS, &outputStreamIds[0],
228 outputStreamIds.size());
229
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800230 if (request.mIsReprocess) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700231 metadata.update(ANDROID_REQUEST_INPUT_STREAMS, &mInputStream.id, 1);
232 }
233
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800234 metadata.update(ANDROID_REQUEST_ID, &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700235 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800236 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
237 __FUNCTION__, mCameraIdStr.string(), submitInfo->mRequestId,
238 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700239
240 metadataRequestList.push_back(metadata);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700241 surfaceMapList.push_back(surfaceMap);
Jianing Wei90e59c92014-03-12 18:29:36 -0700242 }
243 mRequestIdCounter++;
244
245 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700246 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
247 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800248 if (err != OK) {
249 String8 msg = String8::format(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800250 "Camera %s: Got error %s (%d) after trying to set streaming request",
251 mCameraIdStr.string(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800252 ALOGE("%s: %s", __FUNCTION__, msg.string());
253 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
254 msg.string());
Jianing Wei90e59c92014-03-12 18:29:36 -0700255 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700256 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700257 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700258 }
259 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700260 err = mDevice->captureList(metadataRequestList, surfaceMapList,
261 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800262 if (err != OK) {
263 String8 msg = String8::format(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800264 "Camera %s: Got error %s (%d) after trying to submit capture request",
265 mCameraIdStr.string(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800266 ALOGE("%s: %s", __FUNCTION__, msg.string());
267 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
268 msg.string());
Jianing Wei90e59c92014-03-12 18:29:36 -0700269 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800270 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700271 }
272
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800273 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.string());
Jianing Wei90e59c92014-03-12 18:29:36 -0700274 return res;
275}
276
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800277binder::Status CameraDeviceClient::cancelRequest(
278 int requestId,
279 /*out*/
280 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700281 ATRACE_CALL();
282 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
283
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800284 status_t err;
285 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700286
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800287 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700288
289 Mutex::Autolock icl(mBinderSerializationLock);
290
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800291 if (!mDevice.get()) {
292 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
293 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700294
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700295 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700296 if (mStreamingRequestId != requestId) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800297 String8 msg = String8::format("Camera %s: Canceling request ID %d doesn't match "
298 "current request ID %d", mCameraIdStr.string(), requestId, mStreamingRequestId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800299 ALOGE("%s: %s", __FUNCTION__, msg.string());
300 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700301 }
302
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800303 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700304
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800305 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800306 ALOGV("%s: Camera %s: Successfully cleared streaming request",
307 __FUNCTION__, mCameraIdStr.string());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700308 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800309 } else {
310 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800311 "Camera %s: Error clearing streaming request: %s (%d)",
312 mCameraIdStr.string(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700313 }
314
315 return res;
316}
317
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800318binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700319 // TODO: Implement this.
Zhijun He1fa89992015-06-01 15:44:31 -0700320 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800321 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700322}
323
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800324binder::Status CameraDeviceClient::endConfigure(bool isConstrainedHighSpeed) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700325 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
326 __FUNCTION__, mInputStream.configured ? 1 : 0,
327 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700328
Zhijun He0effd522016-03-04 10:22:27 -0800329 binder::Status res;
330 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
331
332 Mutex::Autolock icl(mBinderSerializationLock);
333
334 if (!mDevice.get()) {
335 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
336 }
337
Zhijun He1fa89992015-06-01 15:44:31 -0700338 // Sanitize the high speed session against necessary capability bit.
339 if (isConstrainedHighSpeed) {
340 CameraMetadata staticInfo = mDevice->info();
341 camera_metadata_entry_t entry = staticInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
342 bool isConstrainedHighSpeedSupported = false;
343 for(size_t i = 0; i < entry.count; ++i) {
344 uint8_t capability = entry.data.u8[i];
345 if (capability == ANDROID_REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO) {
346 isConstrainedHighSpeedSupported = true;
347 break;
348 }
349 }
350 if (!isConstrainedHighSpeedSupported) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800351 String8 msg = String8::format(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800352 "Camera %s: Try to create a constrained high speed configuration on a device"
353 " that doesn't support it.", mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800354 ALOGE("%s: %s", __FUNCTION__, msg.string());
355 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
356 msg.string());
Zhijun He1fa89992015-06-01 15:44:31 -0700357 }
358 }
359
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800360 status_t err = mDevice->configureStreams(isConstrainedHighSpeed);
Eino-Ville Talvalaace80582016-03-18 13:27:35 -0700361 if (err == BAD_VALUE) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800362 String8 msg = String8::format("Camera %s: Unsupported set of inputs/outputs provided",
363 mCameraIdStr.string());
Zhijun He5d677d12016-05-29 16:52:39 -0700364 ALOGE("%s: %s", __FUNCTION__, msg.string());
365 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Eino-Ville Talvalaace80582016-03-18 13:27:35 -0700366 } else if (err != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800367 String8 msg = String8::format("Camera %s: Error configuring streams: %s (%d)",
368 mCameraIdStr.string(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -0700369 ALOGE("%s: %s", __FUNCTION__, msg.string());
370 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800371 }
372
373 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700374}
375
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800376binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700377 ATRACE_CALL();
378 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
379
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800380 binder::Status res;
381 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700382
383 Mutex::Autolock icl(mBinderSerializationLock);
384
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800385 if (!mDevice.get()) {
386 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
387 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700388
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700389 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700390 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700391 ssize_t dIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700392
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700393 if (mInputStream.configured && mInputStream.id == streamId) {
394 isInput = true;
395 } else {
396 // Guard against trying to delete non-created streams
397 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700398 if (streamId == mStreamMap.valueAt(i).streamId()) {
399 surfaces.push_back(mStreamMap.keyAt(i));
400 }
401 }
402
403 // See if this stream is one of the deferred streams.
404 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
405 if (streamId == mDeferredStreams[i]) {
406 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700407 break;
408 }
409 }
410
Shuzhen Wang0129d522016-10-30 22:43:41 -0700411 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
412 String8 msg = String8::format("Camera %s: Invalid stream ID (%d) specified, no such"
413 " stream created yet", mCameraIdStr.string(), streamId);
414 ALOGW("%s: %s", __FUNCTION__, msg.string());
415 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700416 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700417 }
418
419 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800420 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700421
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800422 if (err != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800423 String8 msg = String8::format("Camera %s: Unexpected error %s (%d) when deleting stream %d",
424 mCameraIdStr.string(), strerror(-err), err, streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800425 ALOGE("%s: %s", __FUNCTION__, msg.string());
426 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
427 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700428 if (isInput) {
429 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700430 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700431 for (auto& surface : surfaces) {
432 mStreamMap.removeItem(surface);
433 }
434
435 if (dIndex != NAME_NOT_FOUND) {
436 mDeferredStreams.removeItemsAt(dIndex);
437 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700438 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700439 }
440
441 return res;
442}
443
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800444binder::Status CameraDeviceClient::createStream(
445 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
446 /*out*/
447 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700448 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700449
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800450 binder::Status res;
451 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700452
453 Mutex::Autolock icl(mBinderSerializationLock);
454
Shuzhen Wang0129d522016-10-30 22:43:41 -0700455 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
456 outputConfiguration.getGraphicBufferProducers();
457 size_t numBufferProducers = bufferProducers.size();
458
459 if (numBufferProducers > MAX_SURFACES_PER_STREAM) {
460 ALOGE("%s: GraphicBufferProducer count %zu for stream exceeds limit of %d",
461 __FUNCTION__, bufferProducers.size(), MAX_SURFACES_PER_STREAM);
462 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Surface count is too high");
463 }
464 if (numBufferProducers == 0) {
465 ALOGE("%s: GraphicBufferProducer count 0 is not valid", __FUNCTION__);
466 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Malformed surface");
467 }
468 size_t deferredConsumerCnt = 0;
469 for (auto bufferProducer : bufferProducers) {
470 if (bufferProducer == nullptr) {
471 deferredConsumerCnt++;
472 }
473 }
474 if (deferredConsumerCnt > MAX_DEFERRED_SURFACES) {
475 ALOGE("%s: %zu deferred consumer is not supported", __FUNCTION__, deferredConsumerCnt);
476 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
477 "More than %d deferred consumer", MAX_DEFERRED_SURFACES);
478 }
479 bool deferredConsumer = deferredConsumerCnt > 0;
480 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 1;
Zhijun He5d677d12016-05-29 16:52:39 -0700481 int surfaceType = outputConfiguration.getSurfaceType();
482 bool validSurfaceType = ((surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) ||
483 (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_TEXTURE));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700484
Zhijun He5d677d12016-05-29 16:52:39 -0700485 if (deferredConsumer && !validSurfaceType) {
486 ALOGE("%s: Target surface is invalid: bufferProducer = %p, surfaceType = %d.",
Shuzhen Wang0129d522016-10-30 22:43:41 -0700487 __FUNCTION__, bufferProducers[0].get(), surfaceType);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800488 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700489 }
Zhijun He5d677d12016-05-29 16:52:39 -0700490
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800491 if (!mDevice.get()) {
492 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
493 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700494
Shuzhen Wang0129d522016-10-30 22:43:41 -0700495 std::vector<sp<Surface>> surfaces;
496 std::vector<sp<IBinder>> binders;
497 int streamWidth, streamHeight, streamFormat;
Zhijun He5d677d12016-05-29 16:52:39 -0700498 int width, height, format;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700499 int32_t streamConsumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -0700500 int32_t consumerUsage;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700501 android_dataspace dataSpace, streamDataSpace;
Zhijun He5d677d12016-05-29 16:52:39 -0700502 status_t err;
503
504 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700505 if (deferredConsumerOnly) {
Zhijun He5d677d12016-05-29 16:52:39 -0700506 return createDeferredSurfaceStreamLocked(outputConfiguration, newStreamId);
507 }
508
Shuzhen Wang0129d522016-10-30 22:43:41 -0700509 bool isFirstSurface = true;
510 streamWidth = -1;
511 streamHeight = -1;
512 streamFormat = -1;
513 streamDataSpace = HAL_DATASPACE_UNKNOWN;
514 streamConsumerUsage = 0;
515
516 for (auto& bufferProducer : bufferProducers) {
517 if (bufferProducer == nullptr) {
518 continue;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700519 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700520
Shuzhen Wang0129d522016-10-30 22:43:41 -0700521 // Don't create multiple streams for the same target surface
522 {
523 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
524 if (index != NAME_NOT_FOUND) {
525 String8 msg = String8::format("Camera %s: Surface already has a stream created for it "
526 "(ID %zd)", mCameraIdStr.string(), index);
527 ALOGW("%s: %s", __FUNCTION__, msg.string());
528 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
529 }
530 }
Eino-Ville Talvala1da3b602013-09-26 15:28:55 -0700531
Shuzhen Wang0129d522016-10-30 22:43:41 -0700532 // HACK b/10949105
533 // Query consumer usage bits to set async operation mode for
534 // GLConsumer using controlledByApp parameter.
535 bool useAsync = false;
536 if ((err = bufferProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS,
537 &consumerUsage)) != OK) {
538 String8 msg = String8::format("Camera %s: Failed to query Surface consumer usage: %s (%d)",
539 mCameraIdStr.string(), strerror(-err), err);
540 ALOGE("%s: %s", __FUNCTION__, msg.string());
541 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
542 }
543 if (consumerUsage & GraphicBuffer::USAGE_HW_TEXTURE) {
544 ALOGW("%s: Camera %s with consumer usage flag: 0x%x: Forcing asynchronous mode for stream",
545 __FUNCTION__, mCameraIdStr.string(), consumerUsage);
546 useAsync = true;
547 }
Ruben Brunkbba75572014-11-20 17:29:50 -0800548
Shuzhen Wang0129d522016-10-30 22:43:41 -0700549 int32_t disallowedFlags = GraphicBuffer::USAGE_HW_VIDEO_ENCODER |
550 GRALLOC_USAGE_RENDERSCRIPT;
551 int32_t allowedFlags = GraphicBuffer::USAGE_SW_READ_MASK |
552 GraphicBuffer::USAGE_HW_TEXTURE |
553 GraphicBuffer::USAGE_HW_COMPOSER;
554 bool flexibleConsumer = (consumerUsage & disallowedFlags) == 0 &&
555 (consumerUsage & allowedFlags) != 0;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700556
Shuzhen Wang0129d522016-10-30 22:43:41 -0700557 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
558 sp<Surface> surface = new Surface(bufferProducer, useAsync);
559 ANativeWindow *anw = surface.get();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700560
Shuzhen Wang0129d522016-10-30 22:43:41 -0700561 if ((err = anw->query(anw, NATIVE_WINDOW_WIDTH, &width)) != OK) {
562 String8 msg = String8::format("Camera %s: Failed to query Surface width: %s (%d)",
563 mCameraIdStr.string(), strerror(-err), err);
564 ALOGE("%s: %s", __FUNCTION__, msg.string());
565 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
566 }
567 if ((err = anw->query(anw, NATIVE_WINDOW_HEIGHT, &height)) != OK) {
568 String8 msg = String8::format("Camera %s: Failed to query Surface height: %s (%d)",
569 mCameraIdStr.string(), strerror(-err), err);
570 ALOGE("%s: %s", __FUNCTION__, msg.string());
571 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
572 }
573 if ((err = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) {
574 String8 msg = String8::format("Camera %s: Failed to query Surface format: %s (%d)",
575 mCameraIdStr.string(), strerror(-err), err);
576 ALOGE("%s: %s", __FUNCTION__, msg.string());
577 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
578 }
579 if ((err = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE,
580 reinterpret_cast<int*>(&dataSpace))) != OK) {
581 String8 msg = String8::format("Camera %s: Failed to query Surface dataspace: %s (%d)",
582 mCameraIdStr.string(), strerror(-err), err);
583 ALOGE("%s: %s", __FUNCTION__, msg.string());
584 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
585 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700586
Shuzhen Wang0129d522016-10-30 22:43:41 -0700587 // FIXME: remove this override since the default format should be
588 // IMPLEMENTATION_DEFINED. b/9487482
589 if (format >= HAL_PIXEL_FORMAT_RGBA_8888 &&
590 format <= HAL_PIXEL_FORMAT_BGRA_8888) {
591 ALOGW("%s: Camera %s: Overriding format %#x to IMPLEMENTATION_DEFINED",
592 __FUNCTION__, mCameraIdStr.string(), format);
593 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
594 }
595 // Round dimensions to the nearest dimensions available for this format
596 if (flexibleConsumer && isPublicFormat(format) &&
597 !CameraDeviceClient::roundBufferDimensionNearest(width, height,
598 format, dataSpace, mDevice->info(), /*out*/&width, /*out*/&height)) {
599 String8 msg = String8::format("Camera %s: No supported stream configurations with "
600 "format %#x defined, failed to create output stream",
601 mCameraIdStr.string(), format);
602 ALOGE("%s: %s", __FUNCTION__, msg.string());
603 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
604 }
605 if (isFirstSurface) {
606 streamWidth = width;
607 streamHeight = height;
608 streamFormat = format;
609 streamDataSpace = dataSpace;
610 streamConsumerUsage = consumerUsage;
611 isFirstSurface = false;
612 }
613 if (width != streamWidth) {
614 String8 msg = String8::format("Camera %s:Surface width doesn't match: %d vs %d",
615 mCameraIdStr.string(), width, streamWidth);
616 ALOGE("%s: %s", __FUNCTION__, msg.string());
617 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
618 }
619 if (height != streamHeight) {
620 String8 msg = String8::format("Camera %s:Surface height doesn't match: %d vs %d",
621 mCameraIdStr.string(), height, streamHeight);
622 ALOGE("%s: %s", __FUNCTION__, msg.string());
623 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
624 }
625 if (format != streamFormat) {
626 String8 msg = String8::format("Camera %s:Surface format doesn't match: %d vs %d",
627 mCameraIdStr.string(), format, streamFormat);
628 ALOGE("%s: %s", __FUNCTION__, msg.string());
629 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
630 }
631 if (dataSpace != streamDataSpace) {
632 String8 msg = String8::format("Camera %s:Surface dataSpace doesn't match: %d vs %d",
633 mCameraIdStr.string(), dataSpace, streamDataSpace);
634 ALOGE("%s: %s", __FUNCTION__, msg.string());
635 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
636 }
637 //At the native side, there isn't a way to check whether 2 surfaces come from the same
638 //surface class type. Use usage flag to approximate the comparison.
639 //TODO: Support surfaces of different surface class type.
640 if (consumerUsage != streamConsumerUsage) {
641 String8 msg = String8::format(
642 "Camera %s:Surface usage flag doesn't match 0x%x vs 0x%x",
643 mCameraIdStr.string(), consumerUsage, streamConsumerUsage);
644 ALOGE("%s: %s", __FUNCTION__, msg.string());
645 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
646 }
647
648 binders.push_back(binder);
649 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800650 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700651
Zhijun He125684a2015-12-26 15:07:30 -0800652 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700653 err = mDevice->createStream(surfaces, deferredConsumer, width, height, format, dataSpace,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800654 static_cast<camera3_stream_rotation_t>(outputConfiguration.getRotation()),
655 &streamId, outputConfiguration.getSurfaceSetID());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700656
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800657 if (err != OK) {
658 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800659 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
660 mCameraIdStr.string(), width, height, format, dataSpace, strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800661 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700662 int i = 0;
663 for (auto& binder : binders) {
664 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
665 __FUNCTION__, binder.get(), streamId, i);
666 mStreamMap.add(binder, StreamSurfaceId(streamId, i++));
667 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800668 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -0700669 " (%d x %d) with format 0x%x.",
670 __FUNCTION__, mCameraIdStr.string(), streamId, width, height, format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700671
Zhijun He5d677d12016-05-29 16:52:39 -0700672 // Set transform flags to ensure preview to be rotated correctly.
673 res = setStreamTransformLocked(streamId);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700674
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800675 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700676 }
677
678 return res;
679}
680
Zhijun He5d677d12016-05-29 16:52:39 -0700681binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
682 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
683 /*out*/
684 int* newStreamId) {
685 int width, height, format, surfaceType;
686 int32_t consumerUsage;
687 android_dataspace dataSpace;
688 status_t err;
689 binder::Status res;
690
691 if (!mDevice.get()) {
692 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
693 }
694
695 // Infer the surface info for deferred surface stream creation.
696 width = outputConfiguration.getWidth();
697 height = outputConfiguration.getHeight();
698 surfaceType = outputConfiguration.getSurfaceType();
699 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
700 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
701 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
702 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
703 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
704 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
705 }
706 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700707 std::vector<sp<Surface>> noSurface;
708 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
709 height, format, dataSpace,
Zhijun He5d677d12016-05-29 16:52:39 -0700710 static_cast<camera3_stream_rotation_t>(outputConfiguration.getRotation()),
711 &streamId, outputConfiguration.getSurfaceSetID(), consumerUsage);
712
713 if (err != OK) {
714 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800715 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
716 mCameraIdStr.string(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -0700717 } else {
718 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
719 // a separate list to track. Once the deferred surface is set, this id will be
720 // relocated to mStreamMap.
721 mDeferredStreams.push_back(streamId);
722
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800723 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -0700724 " (%d x %d) stream with format 0x%x.",
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800725 __FUNCTION__, mCameraIdStr.string(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -0700726
727 // Set transform flags to ensure preview to be rotated correctly.
728 res = setStreamTransformLocked(streamId);
729
730 *newStreamId = streamId;
731 }
732 return res;
733}
734
735binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId) {
736 int32_t transform = 0;
737 status_t err;
738 binder::Status res;
739
740 if (!mDevice.get()) {
741 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
742 }
743
744 err = getRotationTransformLocked(&transform);
745 if (err != OK) {
746 // Error logged by getRotationTransformLocked.
747 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
748 "Unable to calculate rotation transform for new stream");
749 }
750
751 err = mDevice->setStreamTransform(streamId, transform);
752 if (err != OK) {
753 String8 msg = String8::format("Failed to set stream transform (stream id %d)",
754 streamId);
755 ALOGE("%s: %s", __FUNCTION__, msg.string());
756 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
757 }
758
759 return res;
760}
Ruben Brunkbba75572014-11-20 17:29:50 -0800761
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800762binder::Status CameraDeviceClient::createInputStream(
763 int width, int height, int format,
764 /*out*/
765 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700766
767 ATRACE_CALL();
768 ALOGV("%s (w = %d, h = %d, f = 0x%x)", __FUNCTION__, width, height, format);
769
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800770 binder::Status res;
771 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700772
773 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800774
775 if (!mDevice.get()) {
776 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
777 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700778
779 if (mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800780 String8 msg = String8::format("Camera %s: Already has an input stream "
781 "configured (ID %zd)", mCameraIdStr.string(), mInputStream.id);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800782 ALOGE("%s: %s", __FUNCTION__, msg.string() );
783 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700784 }
785
786 int streamId = -1;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800787 status_t err = mDevice->createInputStream(width, height, format, &streamId);
788 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700789 mInputStream.configured = true;
790 mInputStream.width = width;
791 mInputStream.height = height;
792 mInputStream.format = format;
793 mInputStream.id = streamId;
794
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800795 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
796 __FUNCTION__, mCameraIdStr.string(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700797
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800798 *newStreamId = streamId;
799 } else {
800 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800801 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.string(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800802 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700803 }
804
805 return res;
806}
807
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800808binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700809
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800810 binder::Status res;
811 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
812
813 if (inputSurface == NULL) {
814 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700815 }
816
817 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800818 if (!mDevice.get()) {
819 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
820 }
821 sp<IGraphicBufferProducer> producer;
822 status_t err = mDevice->getInputBufferProducer(&producer);
823 if (err != OK) {
824 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800825 "Camera %s: Error getting input Surface: %s (%d)",
826 mCameraIdStr.string(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800827 } else {
828 inputSurface->name = String16("CameraInput");
829 inputSurface->graphicBufferProducer = producer;
830 }
831 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700832}
833
Eman Copty6d7af0e2016-06-17 20:46:40 -0700834bool CameraDeviceClient::isPublicFormat(int32_t format)
835{
836 switch(format) {
837 case HAL_PIXEL_FORMAT_RGBA_8888:
838 case HAL_PIXEL_FORMAT_RGBX_8888:
839 case HAL_PIXEL_FORMAT_RGB_888:
840 case HAL_PIXEL_FORMAT_RGB_565:
841 case HAL_PIXEL_FORMAT_BGRA_8888:
842 case HAL_PIXEL_FORMAT_YV12:
843 case HAL_PIXEL_FORMAT_Y8:
844 case HAL_PIXEL_FORMAT_Y16:
845 case HAL_PIXEL_FORMAT_RAW16:
846 case HAL_PIXEL_FORMAT_RAW10:
847 case HAL_PIXEL_FORMAT_RAW12:
848 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
849 case HAL_PIXEL_FORMAT_BLOB:
850 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
851 case HAL_PIXEL_FORMAT_YCbCr_420_888:
852 case HAL_PIXEL_FORMAT_YCbCr_422_888:
853 case HAL_PIXEL_FORMAT_YCbCr_444_888:
854 case HAL_PIXEL_FORMAT_FLEX_RGB_888:
855 case HAL_PIXEL_FORMAT_FLEX_RGBA_8888:
856 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
857 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
858 case HAL_PIXEL_FORMAT_YCbCr_422_I:
859 return true;
860 default:
861 return false;
862 }
863}
864
Ruben Brunkbba75572014-11-20 17:29:50 -0800865bool CameraDeviceClient::roundBufferDimensionNearest(int32_t width, int32_t height,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800866 int32_t format, android_dataspace dataSpace, const CameraMetadata& info,
Ruben Brunkbba75572014-11-20 17:29:50 -0800867 /*out*/int32_t* outWidth, /*out*/int32_t* outHeight) {
868
869 camera_metadata_ro_entry streamConfigs =
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800870 (dataSpace == HAL_DATASPACE_DEPTH) ?
871 info.find(ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS) :
Ruben Brunkbba75572014-11-20 17:29:50 -0800872 info.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS);
873
874 int32_t bestWidth = -1;
875 int32_t bestHeight = -1;
876
877 // Iterate through listed stream configurations and find the one with the smallest euclidean
878 // distance from the given dimensions for the given format.
879 for (size_t i = 0; i < streamConfigs.count; i += 4) {
880 int32_t fmt = streamConfigs.data.i32[i];
881 int32_t w = streamConfigs.data.i32[i + 1];
882 int32_t h = streamConfigs.data.i32[i + 2];
883
884 // Ignore input/output type for now
885 if (fmt == format) {
886 if (w == width && h == height) {
887 bestWidth = width;
888 bestHeight = height;
889 break;
890 } else if (w <= ROUNDING_WIDTH_CAP && (bestWidth == -1 ||
891 CameraDeviceClient::euclidDistSquare(w, h, width, height) <
892 CameraDeviceClient::euclidDistSquare(bestWidth, bestHeight, width, height))) {
893 bestWidth = w;
894 bestHeight = h;
895 }
896 }
897 }
898
899 if (bestWidth == -1) {
900 // Return false if no configurations for this format were listed
901 return false;
902 }
903
904 // Set the outputs to the closet width/height
905 if (outWidth != NULL) {
906 *outWidth = bestWidth;
907 }
908 if (outHeight != NULL) {
909 *outHeight = bestHeight;
910 }
911
912 // Return true if at least one configuration for this format was listed
913 return true;
914}
915
916int64_t CameraDeviceClient::euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1) {
917 int64_t d0 = x0 - x1;
918 int64_t d1 = y0 - y1;
919 return d0 * d0 + d1 * d1;
920}
921
Igor Murashkine7ee7632013-06-11 18:10:18 -0700922// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800923binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
924 /*out*/
925 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700926{
927 ATRACE_CALL();
928 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
929
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800930 binder::Status res;
931 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700932
933 Mutex::Autolock icl(mBinderSerializationLock);
934
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800935 if (!mDevice.get()) {
936 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
937 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700938
939 CameraMetadata metadata;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800940 status_t err;
941 if ( (err = mDevice->createDefaultRequest(templateId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -0700942 request != NULL) {
943
944 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -0800945 } else if (err == BAD_VALUE) {
946 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800947 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
948 mCameraIdStr.string(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -0800949
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800950 } else {
951 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800952 "Camera %s: Error creating default request for template %d: %s (%d)",
953 mCameraIdStr.string(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700954 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700955 return res;
956}
957
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800958binder::Status CameraDeviceClient::getCameraInfo(
959 /*out*/
960 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700961{
962 ATRACE_CALL();
963 ALOGV("%s", __FUNCTION__);
964
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800965 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700966
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800967 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700968
969 Mutex::Autolock icl(mBinderSerializationLock);
970
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800971 if (!mDevice.get()) {
972 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
973 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700974
Igor Murashkin099b4572013-07-12 17:52:16 -0700975 if (info != NULL) {
976 *info = mDevice->info(); // static camera metadata
977 // TODO: merge with device-specific camera metadata
978 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700979
980 return res;
981}
982
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800983binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -0700984{
985 ATRACE_CALL();
986 ALOGV("%s", __FUNCTION__);
987
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800988 binder::Status res;
989 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -0700990
991 Mutex::Autolock icl(mBinderSerializationLock);
992
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800993 if (!mDevice.get()) {
994 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
995 }
Zhijun He2ab500c2013-07-23 08:02:53 -0700996
997 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700998 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700999 if (mStreamingRequestId != REQUEST_ID_NONE) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001000 String8 msg = String8::format(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001001 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
1002 mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001003 ALOGE("%s: %s", __FUNCTION__, msg.string());
1004 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Zhijun He2ab500c2013-07-23 08:02:53 -07001005 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001006 status_t err = mDevice->waitUntilDrained();
1007 if (err != OK) {
1008 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001009 "Camera %s: Error waiting to drain: %s (%d)",
1010 mCameraIdStr.string(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001011 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001012 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001013 return res;
1014}
1015
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001016binder::Status CameraDeviceClient::flush(
1017 /*out*/
1018 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001019 ATRACE_CALL();
1020 ALOGV("%s", __FUNCTION__);
1021
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001022 binder::Status res;
1023 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001024
1025 Mutex::Autolock icl(mBinderSerializationLock);
1026
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001027 if (!mDevice.get()) {
1028 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1029 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001030
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001031 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001032 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001033 status_t err = mDevice->flush(lastFrameNumber);
1034 if (err != OK) {
1035 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001036 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.string(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001037 }
1038 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001039}
1040
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001041binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001042 ATRACE_CALL();
1043 ALOGV("%s", __FUNCTION__);
1044
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001045 binder::Status res;
1046 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001047
1048 Mutex::Autolock icl(mBinderSerializationLock);
1049
1050 // Guard against trying to prepare non-created streams
1051 ssize_t index = NAME_NOT_FOUND;
1052 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001053 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001054 index = i;
1055 break;
1056 }
1057 }
1058
1059 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001060 String8 msg = String8::format("Camera %s: Invalid stream ID (%d) specified, no stream "
1061 "with that ID exists", mCameraIdStr.string(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001062 ALOGW("%s: %s", __FUNCTION__, msg.string());
1063 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001064 }
1065
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001066 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1067 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001068 status_t err = mDevice->prepare(streamId);
1069 if (err == BAD_VALUE) {
1070 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001071 "Camera %s: Stream %d has already been used, and cannot be prepared",
1072 mCameraIdStr.string(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001073 } else if (err != OK) {
1074 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001075 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.string(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001076 strerror(-err), err);
1077 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001078 return res;
1079}
1080
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001081binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001082 ATRACE_CALL();
1083 ALOGV("%s", __FUNCTION__);
1084
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001085 binder::Status res;
1086 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001087
1088 Mutex::Autolock icl(mBinderSerializationLock);
1089
1090 // Guard against trying to prepare non-created streams
1091 ssize_t index = NAME_NOT_FOUND;
1092 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001093 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001094 index = i;
1095 break;
1096 }
1097 }
1098
1099 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001100 String8 msg = String8::format("Camera %s: Invalid stream ID (%d) specified, no stream "
1101 "with that ID exists", mCameraIdStr.string(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001102 ALOGW("%s: %s", __FUNCTION__, msg.string());
1103 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001104 }
1105
1106 if (maxCount <= 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001107 String8 msg = String8::format("Camera %s: maxCount (%d) must be greater than 0",
1108 mCameraIdStr.string(), maxCount);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001109 ALOGE("%s: %s", __FUNCTION__, msg.string());
1110 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001111 }
1112
1113 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1114 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001115 status_t err = mDevice->prepare(maxCount, streamId);
1116 if (err == BAD_VALUE) {
1117 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001118 "Camera %s: Stream %d has already been used, and cannot be prepared",
1119 mCameraIdStr.string(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001120 } else if (err != OK) {
1121 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001122 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.string(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001123 strerror(-err), err);
1124 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001125
1126 return res;
1127}
1128
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001129binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001130 ATRACE_CALL();
1131 ALOGV("%s", __FUNCTION__);
1132
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001133 binder::Status res;
1134 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001135
1136 Mutex::Autolock icl(mBinderSerializationLock);
1137
1138 // Guard against trying to prepare non-created streams
1139 ssize_t index = NAME_NOT_FOUND;
1140 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001141 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001142 index = i;
1143 break;
1144 }
1145 }
1146
1147 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001148 String8 msg = String8::format("Camera %s: Invalid stream ID (%d) specified, no stream "
1149 "with that ID exists", mCameraIdStr.string(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001150 ALOGW("%s: %s", __FUNCTION__, msg.string());
1151 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001152 }
1153
1154 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1155 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001156 status_t err = mDevice->tearDown(streamId);
1157 if (err == BAD_VALUE) {
1158 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001159 "Camera %s: Stream %d is still in use, cannot be torn down",
1160 mCameraIdStr.string(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001161 } else if (err != OK) {
1162 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001163 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.string(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001164 strerror(-err), err);
1165 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001166
1167 return res;
1168}
1169
Zhijun He5d677d12016-05-29 16:52:39 -07001170binder::Status CameraDeviceClient::setDeferredConfiguration(int32_t streamId,
1171 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1172 ATRACE_CALL();
1173
1174 binder::Status res;
1175 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1176
1177 Mutex::Autolock icl(mBinderSerializationLock);
1178
Shuzhen Wang0129d522016-10-30 22:43:41 -07001179 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1180 outputConfiguration.getGraphicBufferProducers();
Zhijun He5d677d12016-05-29 16:52:39 -07001181
1182 // Client code should guarantee that the surface is from SurfaceView or SurfaceTexture.
Shuzhen Wang0129d522016-10-30 22:43:41 -07001183 // And it's also saved in the last entry of graphicBufferProducer list
1184 if (bufferProducers.size() == 0) {
1185 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001186 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1187 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001188
1189 // Right now, only first surface in the OutputConfiguration is allowed to be
1190 // deferred. And all other surfaces are checked to be the same (not null) at
1191 // the Java side.
1192 sp<IGraphicBufferProducer> bufferProducer = bufferProducers[0];
1193 if (bufferProducer == nullptr) {
1194 ALOGE("%s: bufferProducer must not be null", __FUNCTION__);
1195 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1196 "Target Surface is invalid");
Zhijun He5d677d12016-05-29 16:52:39 -07001197 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001198
1199 // Check if this stream id is one of the deferred only streams
1200 ssize_t index = NAME_NOT_FOUND;
1201 if (bufferProducers.size() == 1) {
1202 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1203 if (streamId == mDeferredStreams[i]) {
1204 index = i;
1205 break;
1206 }
1207 }
1208
1209 if (index == NAME_NOT_FOUND) {
1210 String8 msg = String8::format("Camera %s: deferred surface is set to a unknown stream"
1211 "(ID %d)", mCameraIdStr.string(), streamId);
1212 ALOGW("%s: %s", __FUNCTION__, msg.string());
1213 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
1214 }
Zhijun He5d677d12016-05-29 16:52:39 -07001215 }
1216
1217 if (!mDevice.get()) {
1218 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1219 }
1220
1221 // Don't create multiple streams for the same target surface
1222 {
1223 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1224 if (index != NAME_NOT_FOUND) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001225 String8 msg = String8::format("Camera %s: Surface already has a stream created "
1226 " for it (ID %zd)", mCameraIdStr.string(), index);
Zhijun He5d677d12016-05-29 16:52:39 -07001227 ALOGW("%s: %s", __FUNCTION__, msg.string());
1228 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
1229 }
1230 }
1231
1232 status_t err;
1233
1234 // Always set to async, as we know the deferred surface is for preview streaming.
1235 sp<Surface> consumerSurface = new Surface(bufferProducer, /*useAsync*/true);
1236
1237 // Finish the deferred stream configuration with the surface.
1238 err = mDevice->setConsumerSurface(streamId, consumerSurface);
1239 if (err == OK) {
1240 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001241 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %zu", __FUNCTION__,
1242 binder.get(), streamId, bufferProducers.size()-1);
1243 mStreamMap.add(binder, StreamSurfaceId(streamId, bufferProducers.size()-1));
1244 if (index != NAME_NOT_FOUND) {
1245 mDeferredStreams.removeItemsAt(index);
1246 }
Zhijun He5d677d12016-05-29 16:52:39 -07001247 } else if (err == NO_INIT) {
1248 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001249 "Camera %s: Deferred surface is invalid: %s (%d)",
1250 mCameraIdStr.string(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001251 } else {
1252 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001253 "Camera %s: Error setting output stream deferred surface: %s (%d)",
1254 mCameraIdStr.string(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001255 }
1256
1257 return res;
1258}
1259
Igor Murashkine7ee7632013-06-11 18:10:18 -07001260status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001261 return BasicClient::dump(fd, args);
1262}
1263
1264status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07001265 String8 result;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001266 result.appendFormat("CameraDeviceClient[%s] (%p) dump:\n",
1267 mCameraIdStr.string(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001268 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001269 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Ruben Brunkcc776712015-02-17 20:18:47 -08001270 result.appendFormat(" Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001271
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001272 result.append(" State:\n");
1273 result.appendFormat(" Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001274 if (mInputStream.configured) {
1275 result.appendFormat(" Current input stream ID: %d\n",
1276 mInputStream.id);
1277 } else {
1278 result.append(" No input stream configured.\n");
1279 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001280 if (!mStreamMap.isEmpty()) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001281 result.append(" Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001282 for (size_t i = 0; i < mStreamMap.size(); i++) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001283 result.appendFormat(" Stream %d Surface %d\n",
1284 mStreamMap.valueAt(i).streamId(),
1285 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001286 }
Zhijun He5d677d12016-05-29 16:52:39 -07001287 } else if (!mDeferredStreams.isEmpty()) {
1288 result.append(" Current deferred surface output stream IDs:\n");
1289 for (auto& streamId : mDeferredStreams) {
1290 result.appendFormat(" Stream %d\n", streamId);
1291 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001292 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001293 result.append(" No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001294 }
1295 write(fd, result.string(), result.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -07001296 // TODO: print dynamic/request section from most recent requests
1297 mFrameProcessor->dump(fd, args);
1298
1299 return dumpDevice(fd, args);
1300}
1301
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001302void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07001303 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001304 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001305 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001306
1307 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07001308 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001309 }
1310}
1311
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001312void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
1313 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
1314
1315 if (remoteCb != 0) {
1316 remoteCb->onRepeatingRequestError(lastFrameNumber);
1317 }
1318
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001319 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001320 mStreamingRequestId = REQUEST_ID_NONE;
1321}
1322
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001323void CameraDeviceClient::notifyIdle() {
1324 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001325 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001326
1327 if (remoteCb != 0) {
1328 remoteCb->onDeviceIdle();
1329 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07001330 Camera2ClientBase::notifyIdle();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001331}
1332
Jianing Weicb0652e2014-03-12 18:29:36 -07001333void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001334 nsecs_t timestamp) {
1335 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001336 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001337 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07001338 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001339 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07001340 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001341}
1342
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001343void CameraDeviceClient::notifyPrepared(int streamId) {
1344 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001345 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001346 if (remoteCb != 0) {
1347 remoteCb->onPrepared(streamId);
1348 }
1349}
1350
Shuzhen Wang9d066012016-09-30 11:30:20 -07001351void CameraDeviceClient::notifyRequestQueueEmpty() {
1352 // Thread safe. Don't bother locking.
1353 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
1354 if (remoteCb != 0) {
1355 remoteCb->onRequestQueueEmpty();
1356 }
1357}
1358
Igor Murashkine7ee7632013-06-11 18:10:18 -07001359void CameraDeviceClient::detachDevice() {
1360 if (mDevice == 0) return;
1361
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001362 ALOGV("Camera %s: Stopping processors", mCameraIdStr.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -07001363
1364 mFrameProcessor->removeListener(FRAME_PROCESSOR_LISTENER_MIN_ID,
1365 FRAME_PROCESSOR_LISTENER_MAX_ID,
1366 /*listener*/this);
1367 mFrameProcessor->requestExit();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001368 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -07001369 mFrameProcessor->join();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001370 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -07001371
1372 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
1373 {
1374 mDevice->clearStreamingRequest();
1375
1376 status_t code;
1377 if ((code = mDevice->waitUntilDrained()) != OK) {
1378 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
1379 code);
1380 }
1381 }
1382
1383 Camera2ClientBase::detachDevice();
1384}
1385
1386/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07001387void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07001388 ATRACE_CALL();
1389 ALOGV("%s", __FUNCTION__);
1390
Igor Murashkin4fb55c12013-08-29 17:43:01 -07001391 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001392 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07001393 if (remoteCb != NULL) {
Jianing Weicb0652e2014-03-12 18:29:36 -07001394 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001395 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001396}
1397
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001398binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07001399 if (mDisconnected) {
1400 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
1401 "The camera device has been disconnected");
1402 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001403 status_t res = checkPid(checkLocation);
1404 return (res == OK) ? binder::Status::ok() :
1405 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
1406 "Attempt to use camera from a different process than original client");
1407}
1408
Igor Murashkine7ee7632013-06-11 18:10:18 -07001409// TODO: move to Camera2ClientBase
1410bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
1411
1412 const int pid = IPCThreadState::self()->getCallingPid();
1413 const int selfPid = getpid();
1414 camera_metadata_entry_t entry;
1415
1416 /**
1417 * Mixin default important security values
1418 * - android.led.transmit = defaulted ON
1419 */
1420 CameraMetadata staticInfo = mDevice->info();
1421 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
1422 for(size_t i = 0; i < entry.count; ++i) {
1423 uint8_t led = entry.data.u8[i];
1424
1425 switch(led) {
1426 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
1427 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
1428 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
1429 metadata.update(ANDROID_LED_TRANSMIT,
1430 &transmitDefault, 1);
1431 }
1432 break;
1433 }
1434 }
1435 }
1436
1437 // We can do anything!
1438 if (pid == selfPid) {
1439 return true;
1440 }
1441
1442 /**
1443 * Permission check special fields in the request
1444 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
1445 */
1446 entry = metadata.find(ANDROID_LED_TRANSMIT);
1447 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
1448 String16 permissionString =
1449 String16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
1450 if (!checkCallingPermission(permissionString)) {
1451 const int uid = IPCThreadState::self()->getCallingUid();
1452 ALOGE("Permission Denial: "
1453 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
1454 return false;
1455 }
1456 }
1457
1458 return true;
1459}
1460
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001461status_t CameraDeviceClient::getRotationTransformLocked(int32_t* transform) {
1462 ALOGV("%s: begin", __FUNCTION__);
1463
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001464 const CameraMetadata& staticInfo = mDevice->info();
Ruben Brunk5698d442014-06-18 10:39:40 -07001465 return CameraUtils::getRotationTransform(staticInfo, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001466}
1467
Igor Murashkine7ee7632013-06-11 18:10:18 -07001468} // namespace android