blob: 2ebd5a80969e276ed2d4bdd1517f13a9d63b3458 [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,
49 int cameraId,
50 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,
70 int cameraId,
71 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();
82 ALOGI("CameraDeviceClient %d: Opened", cameraId);
83}
84
Yin-Chia Yehe074a932015-01-30 10:29:02 -080085status_t CameraDeviceClient::initialize(CameraModule *module)
Igor Murashkine7ee7632013-06-11 18:10:18 -070086{
87 ATRACE_CALL();
88 status_t res;
89
90 res = Camera2ClientBase::initialize(module);
91 if (res != OK) {
92 return res;
93 }
94
95 String8 threadName;
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070096 mFrameProcessor = new FrameProcessorBase(mDevice);
Igor Murashkine7ee7632013-06-11 18:10:18 -070097 threadName = String8::format("CDU-%d-FrameProc", mCameraId);
98 mFrameProcessor->run(threadName.string());
99
100 mFrameProcessor->registerListener(FRAME_PROCESSOR_LISTENER_MIN_ID,
101 FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800102 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700103 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700104
105 return OK;
106}
107
108CameraDeviceClient::~CameraDeviceClient() {
109}
110
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800111binder::Status CameraDeviceClient::submitRequest(
112 const hardware::camera2::CaptureRequest& request,
113 bool streaming,
114 /*out*/
115 hardware::camera2::utils::SubmitInfo *submitInfo) {
116 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
117 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700118}
119
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800120binder::Status CameraDeviceClient::submitRequestList(
121 const std::vector<hardware::camera2::CaptureRequest>& requests,
122 bool streaming,
123 /*out*/
124 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700125 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700126 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700127
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800128 binder::Status res = binder::Status::ok();
129 status_t err;
130 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
131 return res;
132 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700133
134 Mutex::Autolock icl(mBinderSerializationLock);
135
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800136 if (!mDevice.get()) {
137 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
138 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700139
140 if (requests.empty()) {
141 ALOGE("%s: Camera %d: Sent null request. Rejecting request.",
142 __FUNCTION__, mCameraId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800143 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700144 }
145
146 List<const CameraMetadata> metadataRequestList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800147 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700148 uint32_t loopCounter = 0;
149
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800150 for (auto&& request: requests) {
151 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700152 if (!mInputStream.configured) {
153 ALOGE("%s: Camera %d: no input stream is configured.", __FUNCTION__, mCameraId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800154 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
155 "No input configured for camera %d but request is for reprocessing",
156 mCameraId);
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700157 } else if (streaming) {
158 ALOGE("%s: Camera %d: streaming reprocess requests not supported.", __FUNCTION__,
159 mCameraId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800160 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
161 "Repeating reprocess requests not supported");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700162 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700163 }
164
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800165 CameraMetadata metadata(request.mMetadata);
Jianing Wei90e59c92014-03-12 18:29:36 -0700166 if (metadata.isEmpty()) {
167 ALOGE("%s: Camera %d: Sent empty metadata packet. Rejecting request.",
168 __FUNCTION__, mCameraId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800169 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
170 "Request settings are empty");
171 } else if (request.mSurfaceList.isEmpty()) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700172 ALOGE("%s: Camera %d: Requests must have at least one surface target. "
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800173 "Rejecting request.", __FUNCTION__, mCameraId);
174 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
175 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700176 }
177
178 if (!enforceRequestPermissions(metadata)) {
179 // Callee logs
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800180 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
181 "Caller does not have permission to change restricted controls");
Jianing Wei90e59c92014-03-12 18:29:36 -0700182 }
183
184 /**
185 * Write in the output stream IDs which we calculate from
186 * the capture request's list of surface targets
187 */
188 Vector<int32_t> outputStreamIds;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800189 outputStreamIds.setCapacity(request.mSurfaceList.size());
190 for (sp<Surface> surface : request.mSurfaceList) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700191 if (surface == 0) continue;
192
193 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Marco Nelissenf8880202014-11-14 07:58:25 -0800194 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
Jianing Wei90e59c92014-03-12 18:29:36 -0700195
196 // Trying to submit request with surface that wasn't created
197 if (idx == NAME_NOT_FOUND) {
198 ALOGE("%s: Camera %d: Tried to submit a request with a surface that"
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800199 " we have not called createStream on",
200 __FUNCTION__, mCameraId);
201 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
202 "Request targets Surface that is not part of current capture session");
Jianing Wei90e59c92014-03-12 18:29:36 -0700203 }
204
205 int streamId = mStreamMap.valueAt(idx);
206 outputStreamIds.push_back(streamId);
207 ALOGV("%s: Camera %d: Appending output stream %d to request",
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800208 __FUNCTION__, mCameraId, streamId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700209 }
210
211 metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS, &outputStreamIds[0],
212 outputStreamIds.size());
213
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800214 if (request.mIsReprocess) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700215 metadata.update(ANDROID_REQUEST_INPUT_STREAMS, &mInputStream.id, 1);
216 }
217
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800218 metadata.update(ANDROID_REQUEST_ID, &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700219 loopCounter++; // loopCounter starts from 1
Mark Salyzyn50468412014-06-18 16:33:43 -0700220 ALOGV("%s: Camera %d: Creating request with ID %d (%d of %zu)",
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800221 __FUNCTION__, mCameraId, submitInfo->mRequestId, loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700222
223 metadataRequestList.push_back(metadata);
224 }
225 mRequestIdCounter++;
226
227 if (streaming) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800228 err = mDevice->setStreamingRequestList(metadataRequestList, &(submitInfo->mLastFrameNumber));
229 if (err != OK) {
230 String8 msg = String8::format(
231 "Camera %d: Got error %s (%d) after trying to set streaming request",
232 mCameraId, strerror(-err), err);
233 ALOGE("%s: %s", __FUNCTION__, msg.string());
234 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
235 msg.string());
Jianing Wei90e59c92014-03-12 18:29:36 -0700236 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700237 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700238 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700239 }
240 } else {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800241 err = mDevice->captureList(metadataRequestList, &(submitInfo->mLastFrameNumber));
242 if (err != OK) {
243 String8 msg = String8::format(
244 "Camera %d: Got error %s (%d) after trying to submit capture request",
245 mCameraId, strerror(-err), err);
246 ALOGE("%s: %s", __FUNCTION__, msg.string());
247 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
248 msg.string());
Jianing Wei90e59c92014-03-12 18:29:36 -0700249 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800250 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700251 }
252
253 ALOGV("%s: Camera %d: End of function", __FUNCTION__, mCameraId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700254 return res;
255}
256
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800257binder::Status CameraDeviceClient::cancelRequest(
258 int requestId,
259 /*out*/
260 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700261 ATRACE_CALL();
262 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
263
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800264 status_t err;
265 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700266
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800267 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700268
269 Mutex::Autolock icl(mBinderSerializationLock);
270
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800271 if (!mDevice.get()) {
272 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
273 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700274
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700275 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700276 if (mStreamingRequestId != requestId) {
277 String8 msg = String8::format("Camera %d: Canceling request ID %d doesn't match "
278 "current request ID %d", mCameraId, requestId, mStreamingRequestId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800279 ALOGE("%s: %s", __FUNCTION__, msg.string());
280 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700281 }
282
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800283 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700284
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800285 if (err == OK) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700286 ALOGV("%s: Camera %d: Successfully cleared streaming request",
287 __FUNCTION__, mCameraId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700288 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800289 } else {
290 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
291 "Camera %d: Error clearing streaming request: %s (%d)",
292 mCameraId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700293 }
294
295 return res;
296}
297
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800298binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700299 // TODO: Implement this.
Zhijun He1fa89992015-06-01 15:44:31 -0700300 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800301 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700302}
303
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800304binder::Status CameraDeviceClient::endConfigure(bool isConstrainedHighSpeed) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700305 ALOGV("%s: ending configure (%d input stream, %zu output streams)",
306 __FUNCTION__, mInputStream.configured ? 1 : 0, mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700307
Zhijun He0effd522016-03-04 10:22:27 -0800308 binder::Status res;
309 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
310
311 Mutex::Autolock icl(mBinderSerializationLock);
312
313 if (!mDevice.get()) {
314 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
315 }
316
Zhijun He1fa89992015-06-01 15:44:31 -0700317 // Sanitize the high speed session against necessary capability bit.
318 if (isConstrainedHighSpeed) {
319 CameraMetadata staticInfo = mDevice->info();
320 camera_metadata_entry_t entry = staticInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
321 bool isConstrainedHighSpeedSupported = false;
322 for(size_t i = 0; i < entry.count; ++i) {
323 uint8_t capability = entry.data.u8[i];
324 if (capability == ANDROID_REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO) {
325 isConstrainedHighSpeedSupported = true;
326 break;
327 }
328 }
329 if (!isConstrainedHighSpeedSupported) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800330 String8 msg = String8::format(
331 "Camera %d: Try to create a constrained high speed configuration on a device"
332 " that doesn't support it.", mCameraId);
333 ALOGE("%s: %s", __FUNCTION__, msg.string());
334 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
335 msg.string());
Zhijun He1fa89992015-06-01 15:44:31 -0700336 }
337 }
338
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800339 status_t err = mDevice->configureStreams(isConstrainedHighSpeed);
Eino-Ville Talvalaace80582016-03-18 13:27:35 -0700340 if (err == BAD_VALUE) {
341 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
342 "Camera %d: Unsupported set of inputs/outputs provided",
343 mCameraId);
344 } else if (err != OK) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800345 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
346 "Camera %d: Error configuring streams: %s (%d)",
347 mCameraId, strerror(-err), err);
348 }
349
350 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700351}
352
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800353binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700354 ATRACE_CALL();
355 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
356
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800357 binder::Status res;
358 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700359
360 Mutex::Autolock icl(mBinderSerializationLock);
361
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800362 if (!mDevice.get()) {
363 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
364 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700365
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700366 bool isInput = false;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700367 ssize_t index = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700368
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700369 if (mInputStream.configured && mInputStream.id == streamId) {
370 isInput = true;
371 } else {
372 // Guard against trying to delete non-created streams
373 for (size_t i = 0; i < mStreamMap.size(); ++i) {
374 if (streamId == mStreamMap.valueAt(i)) {
375 index = i;
376 break;
377 }
378 }
379
380 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800381 String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no such "
382 "stream created yet", mCameraId, streamId);
383 ALOGW("%s: %s", __FUNCTION__, msg.string());
384 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700385 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700386 }
387
388 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800389 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700390
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800391 if (err != OK) {
392 String8 msg = String8::format("Camera %d: Unexpected error %s (%d) when deleting stream %d",
393 mCameraId, strerror(-err), err, streamId);
394 ALOGE("%s: %s", __FUNCTION__, msg.string());
395 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
396 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700397 if (isInput) {
398 mInputStream.configured = false;
399 } else {
400 mStreamMap.removeItemsAt(index);
401 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700402 }
403
404 return res;
405}
406
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800407binder::Status CameraDeviceClient::createStream(
408 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
409 /*out*/
410 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700411 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700412
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800413 binder::Status res;
414 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700415
416 Mutex::Autolock icl(mBinderSerializationLock);
417
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700418 sp<IGraphicBufferProducer> bufferProducer = outputConfiguration.getGraphicBufferProducer();
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700419 if (bufferProducer == NULL) {
420 ALOGE("%s: bufferProducer must not be null", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800421 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700422 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800423 if (!mDevice.get()) {
424 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
425 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700426
427 // Don't create multiple streams for the same target surface
428 {
Marco Nelissenf8880202014-11-14 07:58:25 -0800429 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
Igor Murashkine7ee7632013-06-11 18:10:18 -0700430 if (index != NAME_NOT_FOUND) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800431 String8 msg = String8::format("Camera %d: Surface already has a stream created for it "
432 "(ID %zd)", mCameraId, index);
433 ALOGW("%s: %s", __FUNCTION__, msg.string());
434 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700435 }
436 }
437
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800438 status_t err;
439
Eino-Ville Talvala1da3b602013-09-26 15:28:55 -0700440 // HACK b/10949105
441 // Query consumer usage bits to set async operation mode for
442 // GLConsumer using controlledByApp parameter.
443 bool useAsync = false;
444 int32_t consumerUsage;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800445 if ((err = bufferProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS,
Eino-Ville Talvala1da3b602013-09-26 15:28:55 -0700446 &consumerUsage)) != OK) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800447 String8 msg = String8::format("Camera %d: Failed to query Surface consumer usage: %s (%d)",
448 mCameraId, strerror(-err), err);
449 ALOGE("%s: %s", __FUNCTION__, msg.string());
450 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Eino-Ville Talvala1da3b602013-09-26 15:28:55 -0700451 }
452 if (consumerUsage & GraphicBuffer::USAGE_HW_TEXTURE) {
453 ALOGW("%s: Camera %d: Forcing asynchronous mode for stream",
454 __FUNCTION__, mCameraId);
455 useAsync = true;
456 }
457
Ruben Brunkbba75572014-11-20 17:29:50 -0800458 int32_t disallowedFlags = GraphicBuffer::USAGE_HW_VIDEO_ENCODER |
459 GRALLOC_USAGE_RENDERSCRIPT;
460 int32_t allowedFlags = GraphicBuffer::USAGE_SW_READ_MASK |
461 GraphicBuffer::USAGE_HW_TEXTURE |
462 GraphicBuffer::USAGE_HW_COMPOSER;
463 bool flexibleConsumer = (consumerUsage & disallowedFlags) == 0 &&
464 (consumerUsage & allowedFlags) != 0;
465
Marco Nelissenf8880202014-11-14 07:58:25 -0800466 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700467 sp<Surface> surface = new Surface(bufferProducer, useAsync);
468 ANativeWindow *anw = surface.get();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700469
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800470 int width, height, format;
471 android_dataspace dataSpace;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700472
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800473 if ((err = anw->query(anw, NATIVE_WINDOW_WIDTH, &width)) != OK) {
474 String8 msg = String8::format("Camera %d: Failed to query Surface width: %s (%d)",
475 mCameraId, strerror(-err), err);
476 ALOGE("%s: %s", __FUNCTION__, msg.string());
477 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700478 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800479 if ((err = anw->query(anw, NATIVE_WINDOW_HEIGHT, &height)) != OK) {
480 String8 msg = String8::format("Camera %d: Failed to query Surface height: %s (%d)",
481 mCameraId, strerror(-err), err);
482 ALOGE("%s: %s", __FUNCTION__, msg.string());
483 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700484 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800485 if ((err = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) {
486 String8 msg = String8::format("Camera %d: Failed to query Surface format: %s (%d)",
487 mCameraId, strerror(-err), err);
488 ALOGE("%s: %s", __FUNCTION__, msg.string());
489 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700490 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800491 if ((err = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800492 reinterpret_cast<int*>(&dataSpace))) != OK) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800493 String8 msg = String8::format("Camera %d: Failed to query Surface dataspace: %s (%d)",
494 mCameraId, strerror(-err), err);
495 ALOGE("%s: %s", __FUNCTION__, msg.string());
496 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800497 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700498
499 // FIXME: remove this override since the default format should be
500 // IMPLEMENTATION_DEFINED. b/9487482
Igor Murashkin15811012013-07-29 12:25:59 -0700501 if (format >= HAL_PIXEL_FORMAT_RGBA_8888 &&
502 format <= HAL_PIXEL_FORMAT_BGRA_8888) {
Ruben Brunkbba75572014-11-20 17:29:50 -0800503 ALOGW("%s: Camera %d: Overriding format %#x to IMPLEMENTATION_DEFINED",
Igor Murashkine7ee7632013-06-11 18:10:18 -0700504 __FUNCTION__, mCameraId, format);
505 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
506 }
507
Ruben Brunkbba75572014-11-20 17:29:50 -0800508 // Round dimensions to the nearest dimensions available for this format
Eman Copty6d7af0e2016-06-17 20:46:40 -0700509 if (flexibleConsumer && isPublicFormat(format) &&
510 !CameraDeviceClient::roundBufferDimensionNearest(width, height,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800511 format, dataSpace, mDevice->info(), /*out*/&width, /*out*/&height)) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800512 String8 msg = String8::format("Camera %d: No supported stream configurations with "
513 "format %#x defined, failed to create output stream", mCameraId, format);
514 ALOGE("%s: %s", __FUNCTION__, msg.string());
515 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Ruben Brunkbba75572014-11-20 17:29:50 -0800516 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700517
Zhijun He125684a2015-12-26 15:07:30 -0800518 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800519 err = mDevice->createStream(surface, width, height, format, dataSpace,
520 static_cast<camera3_stream_rotation_t>(outputConfiguration.getRotation()),
521 &streamId, outputConfiguration.getSurfaceSetID());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700522
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800523 if (err != OK) {
524 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
525 "Camera %d: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
526 mCameraId, width, height, format, dataSpace, strerror(-err), err);
527 } else {
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800528 mStreamMap.add(binder, streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700529
530 ALOGV("%s: Camera %d: Successfully created a new stream ID %d",
531 __FUNCTION__, mCameraId, streamId);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700532
533 /**
534 * Set the stream transform flags to automatically
535 * rotate the camera stream for preview use cases.
536 */
537 int32_t transform = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800538 err = getRotationTransformLocked(&transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700539
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800540 if (err != OK) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700541 // Error logged by getRotationTransformLocked.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800542 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
543 "Unable to calculate rotation transform for new stream");
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700544 }
545
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800546 err = mDevice->setStreamTransform(streamId, transform);
547 if (err != OK) {
548 String8 msg = String8::format("Failed to set stream transform (stream id %d)",
549 streamId);
550 ALOGE("%s: %s", __FUNCTION__, msg.string());
551 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700552 }
553
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800554 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700555 }
556
557 return res;
558}
559
Ruben Brunkbba75572014-11-20 17:29:50 -0800560
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800561binder::Status CameraDeviceClient::createInputStream(
562 int width, int height, int format,
563 /*out*/
564 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700565
566 ATRACE_CALL();
567 ALOGV("%s (w = %d, h = %d, f = 0x%x)", __FUNCTION__, width, height, format);
568
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800569 binder::Status res;
570 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700571
572 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800573
574 if (!mDevice.get()) {
575 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
576 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700577
578 if (mInputStream.configured) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800579 String8 msg = String8::format("Camera %d: Already has an input stream "
580 "configured (ID %zd)", mCameraId, mInputStream.id);
581 ALOGE("%s: %s", __FUNCTION__, msg.string() );
582 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700583 }
584
585 int streamId = -1;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800586 status_t err = mDevice->createInputStream(width, height, format, &streamId);
587 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700588 mInputStream.configured = true;
589 mInputStream.width = width;
590 mInputStream.height = height;
591 mInputStream.format = format;
592 mInputStream.id = streamId;
593
594 ALOGV("%s: Camera %d: Successfully created a new input stream ID %d",
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800595 __FUNCTION__, mCameraId, streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700596
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800597 *newStreamId = streamId;
598 } else {
599 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
600 "Camera %d: Error creating new input stream: %s (%d)", mCameraId,
601 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700602 }
603
604 return res;
605}
606
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800607binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700608
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800609 binder::Status res;
610 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
611
612 if (inputSurface == NULL) {
613 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700614 }
615
616 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800617 if (!mDevice.get()) {
618 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
619 }
620 sp<IGraphicBufferProducer> producer;
621 status_t err = mDevice->getInputBufferProducer(&producer);
622 if (err != OK) {
623 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
624 "Camera %d: Error getting input Surface: %s (%d)",
625 mCameraId, strerror(-err), err);
626 } else {
627 inputSurface->name = String16("CameraInput");
628 inputSurface->graphicBufferProducer = producer;
629 }
630 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700631}
632
Eman Copty6d7af0e2016-06-17 20:46:40 -0700633bool CameraDeviceClient::isPublicFormat(int32_t format)
634{
635 switch(format) {
636 case HAL_PIXEL_FORMAT_RGBA_8888:
637 case HAL_PIXEL_FORMAT_RGBX_8888:
638 case HAL_PIXEL_FORMAT_RGB_888:
639 case HAL_PIXEL_FORMAT_RGB_565:
640 case HAL_PIXEL_FORMAT_BGRA_8888:
641 case HAL_PIXEL_FORMAT_YV12:
642 case HAL_PIXEL_FORMAT_Y8:
643 case HAL_PIXEL_FORMAT_Y16:
644 case HAL_PIXEL_FORMAT_RAW16:
645 case HAL_PIXEL_FORMAT_RAW10:
646 case HAL_PIXEL_FORMAT_RAW12:
647 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
648 case HAL_PIXEL_FORMAT_BLOB:
649 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
650 case HAL_PIXEL_FORMAT_YCbCr_420_888:
651 case HAL_PIXEL_FORMAT_YCbCr_422_888:
652 case HAL_PIXEL_FORMAT_YCbCr_444_888:
653 case HAL_PIXEL_FORMAT_FLEX_RGB_888:
654 case HAL_PIXEL_FORMAT_FLEX_RGBA_8888:
655 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
656 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
657 case HAL_PIXEL_FORMAT_YCbCr_422_I:
658 return true;
659 default:
660 return false;
661 }
662}
663
Ruben Brunkbba75572014-11-20 17:29:50 -0800664bool CameraDeviceClient::roundBufferDimensionNearest(int32_t width, int32_t height,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800665 int32_t format, android_dataspace dataSpace, const CameraMetadata& info,
Ruben Brunkbba75572014-11-20 17:29:50 -0800666 /*out*/int32_t* outWidth, /*out*/int32_t* outHeight) {
667
668 camera_metadata_ro_entry streamConfigs =
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800669 (dataSpace == HAL_DATASPACE_DEPTH) ?
670 info.find(ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS) :
Ruben Brunkbba75572014-11-20 17:29:50 -0800671 info.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS);
672
673 int32_t bestWidth = -1;
674 int32_t bestHeight = -1;
675
676 // Iterate through listed stream configurations and find the one with the smallest euclidean
677 // distance from the given dimensions for the given format.
678 for (size_t i = 0; i < streamConfigs.count; i += 4) {
679 int32_t fmt = streamConfigs.data.i32[i];
680 int32_t w = streamConfigs.data.i32[i + 1];
681 int32_t h = streamConfigs.data.i32[i + 2];
682
683 // Ignore input/output type for now
684 if (fmt == format) {
685 if (w == width && h == height) {
686 bestWidth = width;
687 bestHeight = height;
688 break;
689 } else if (w <= ROUNDING_WIDTH_CAP && (bestWidth == -1 ||
690 CameraDeviceClient::euclidDistSquare(w, h, width, height) <
691 CameraDeviceClient::euclidDistSquare(bestWidth, bestHeight, width, height))) {
692 bestWidth = w;
693 bestHeight = h;
694 }
695 }
696 }
697
698 if (bestWidth == -1) {
699 // Return false if no configurations for this format were listed
700 return false;
701 }
702
703 // Set the outputs to the closet width/height
704 if (outWidth != NULL) {
705 *outWidth = bestWidth;
706 }
707 if (outHeight != NULL) {
708 *outHeight = bestHeight;
709 }
710
711 // Return true if at least one configuration for this format was listed
712 return true;
713}
714
715int64_t CameraDeviceClient::euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1) {
716 int64_t d0 = x0 - x1;
717 int64_t d1 = y0 - y1;
718 return d0 * d0 + d1 * d1;
719}
720
Igor Murashkine7ee7632013-06-11 18:10:18 -0700721// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800722binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
723 /*out*/
724 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700725{
726 ATRACE_CALL();
727 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
728
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800729 binder::Status res;
730 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700731
732 Mutex::Autolock icl(mBinderSerializationLock);
733
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800734 if (!mDevice.get()) {
735 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
736 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700737
738 CameraMetadata metadata;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800739 status_t err;
740 if ( (err = mDevice->createDefaultRequest(templateId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -0700741 request != NULL) {
742
743 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -0800744 } else if (err == BAD_VALUE) {
745 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
746 "Camera %d: Template ID %d is invalid or not supported: %s (%d)",
747 mCameraId, templateId, strerror(-err), err);
748
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800749 } else {
750 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
751 "Camera %d: Error creating default request for template %d: %s (%d)",
752 mCameraId, templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700753 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700754 return res;
755}
756
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800757binder::Status CameraDeviceClient::getCameraInfo(
758 /*out*/
759 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700760{
761 ATRACE_CALL();
762 ALOGV("%s", __FUNCTION__);
763
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800764 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700765
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800766 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700767
768 Mutex::Autolock icl(mBinderSerializationLock);
769
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800770 if (!mDevice.get()) {
771 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
772 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700773
Igor Murashkin099b4572013-07-12 17:52:16 -0700774 if (info != NULL) {
775 *info = mDevice->info(); // static camera metadata
776 // TODO: merge with device-specific camera metadata
777 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700778
779 return res;
780}
781
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800782binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -0700783{
784 ATRACE_CALL();
785 ALOGV("%s", __FUNCTION__);
786
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800787 binder::Status res;
788 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -0700789
790 Mutex::Autolock icl(mBinderSerializationLock);
791
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800792 if (!mDevice.get()) {
793 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
794 }
Zhijun He2ab500c2013-07-23 08:02:53 -0700795
796 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700797 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700798 if (mStreamingRequestId != REQUEST_ID_NONE) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800799 String8 msg = String8::format(
800 "Camera %d: Try to waitUntilIdle when there are active streaming requests",
801 mCameraId);
802 ALOGE("%s: %s", __FUNCTION__, msg.string());
803 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
Zhijun He2ab500c2013-07-23 08:02:53 -0700804 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800805 status_t err = mDevice->waitUntilDrained();
806 if (err != OK) {
807 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
808 "Camera %d: Error waiting to drain: %s (%d)",
809 mCameraId, strerror(-err), err);
810 }
Zhijun He2ab500c2013-07-23 08:02:53 -0700811 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -0700812 return res;
813}
814
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800815binder::Status CameraDeviceClient::flush(
816 /*out*/
817 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700818 ATRACE_CALL();
819 ALOGV("%s", __FUNCTION__);
820
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800821 binder::Status res;
822 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700823
824 Mutex::Autolock icl(mBinderSerializationLock);
825
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800826 if (!mDevice.get()) {
827 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
828 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700829
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700830 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700831 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800832 status_t err = mDevice->flush(lastFrameNumber);
833 if (err != OK) {
834 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
835 "Camera %d: Error flushing device: %s (%d)", mCameraId, strerror(-err), err);
836 }
837 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700838}
839
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800840binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700841 ATRACE_CALL();
842 ALOGV("%s", __FUNCTION__);
843
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800844 binder::Status res;
845 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700846
847 Mutex::Autolock icl(mBinderSerializationLock);
848
849 // Guard against trying to prepare non-created streams
850 ssize_t index = NAME_NOT_FOUND;
851 for (size_t i = 0; i < mStreamMap.size(); ++i) {
852 if (streamId == mStreamMap.valueAt(i)) {
853 index = i;
854 break;
855 }
856 }
857
858 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800859 String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
860 "with that ID exists", mCameraId, streamId);
861 ALOGW("%s: %s", __FUNCTION__, msg.string());
862 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700863 }
864
Eino-Ville Talvala261394e2015-05-13 14:28:38 -0700865 // Also returns BAD_VALUE if stream ID was not valid, or stream already
866 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800867 status_t err = mDevice->prepare(streamId);
868 if (err == BAD_VALUE) {
869 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
870 "Camera %d: Stream %d has already been used, and cannot be prepared",
871 mCameraId, streamId);
872 } else if (err != OK) {
873 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
874 "Camera %d: Error preparing stream %d: %s (%d)", mCameraId, streamId,
875 strerror(-err), err);
876 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700877 return res;
878}
879
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800880binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -0700881 ATRACE_CALL();
882 ALOGV("%s", __FUNCTION__);
883
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800884 binder::Status res;
885 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700886
887 Mutex::Autolock icl(mBinderSerializationLock);
888
889 // Guard against trying to prepare non-created streams
890 ssize_t index = NAME_NOT_FOUND;
891 for (size_t i = 0; i < mStreamMap.size(); ++i) {
892 if (streamId == mStreamMap.valueAt(i)) {
893 index = i;
894 break;
895 }
896 }
897
898 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800899 String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
900 "with that ID exists", mCameraId, streamId);
901 ALOGW("%s: %s", __FUNCTION__, msg.string());
902 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Ruben Brunkc78ac262015-08-13 17:58:46 -0700903 }
904
905 if (maxCount <= 0) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800906 String8 msg = String8::format("Camera %d: maxCount (%d) must be greater than 0",
907 mCameraId, maxCount);
908 ALOGE("%s: %s", __FUNCTION__, msg.string());
909 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Ruben Brunkc78ac262015-08-13 17:58:46 -0700910 }
911
912 // Also returns BAD_VALUE if stream ID was not valid, or stream already
913 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800914 status_t err = mDevice->prepare(maxCount, streamId);
915 if (err == BAD_VALUE) {
916 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
917 "Camera %d: Stream %d has already been used, and cannot be prepared",
918 mCameraId, streamId);
919 } else if (err != OK) {
920 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
921 "Camera %d: Error preparing stream %d: %s (%d)", mCameraId, streamId,
922 strerror(-err), err);
923 }
Ruben Brunkc78ac262015-08-13 17:58:46 -0700924
925 return res;
926}
927
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800928binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700929 ATRACE_CALL();
930 ALOGV("%s", __FUNCTION__);
931
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800932 binder::Status res;
933 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700934
935 Mutex::Autolock icl(mBinderSerializationLock);
936
937 // Guard against trying to prepare non-created streams
938 ssize_t index = NAME_NOT_FOUND;
939 for (size_t i = 0; i < mStreamMap.size(); ++i) {
940 if (streamId == mStreamMap.valueAt(i)) {
941 index = i;
942 break;
943 }
944 }
945
946 if (index == NAME_NOT_FOUND) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800947 String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
948 "with that ID exists", mCameraId, streamId);
949 ALOGW("%s: %s", __FUNCTION__, msg.string());
950 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700951 }
952
953 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
954 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800955 status_t err = mDevice->tearDown(streamId);
956 if (err == BAD_VALUE) {
957 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
958 "Camera %d: Stream %d is still in use, cannot be torn down",
959 mCameraId, streamId);
960 } else if (err != OK) {
961 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
962 "Camera %d: Error tearing down stream %d: %s (%d)", mCameraId, streamId,
963 strerror(-err), err);
964 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700965
966 return res;
967}
968
Igor Murashkine7ee7632013-06-11 18:10:18 -0700969status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800970 return BasicClient::dump(fd, args);
971}
972
973status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700974 String8 result;
Eino-Ville Talvala67489d22014-09-18 15:52:02 -0700975 result.appendFormat("CameraDeviceClient[%d] (%p) dump:\n",
Igor Murashkine7ee7632013-06-11 18:10:18 -0700976 mCameraId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800977 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -0800978 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Ruben Brunkcc776712015-02-17 20:18:47 -0800979 result.appendFormat(" Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700980
Eino-Ville Talvala67489d22014-09-18 15:52:02 -0700981 result.append(" State:\n");
982 result.appendFormat(" Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700983 if (mInputStream.configured) {
984 result.appendFormat(" Current input stream ID: %d\n",
985 mInputStream.id);
986 } else {
987 result.append(" No input stream configured.\n");
988 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -0700989 if (!mStreamMap.isEmpty()) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700990 result.append(" Current output stream IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -0700991 for (size_t i = 0; i < mStreamMap.size(); i++) {
992 result.appendFormat(" Stream %d\n", mStreamMap.valueAt(i));
993 }
994 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700995 result.append(" No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -0700996 }
997 write(fd, result.string(), result.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700998 // TODO: print dynamic/request section from most recent requests
999 mFrameProcessor->dump(fd, args);
1000
1001 return dumpDevice(fd, args);
1002}
1003
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001004void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07001005 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001006 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001007 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001008
1009 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07001010 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001011 }
1012}
1013
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001014void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
1015 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
1016
1017 if (remoteCb != 0) {
1018 remoteCb->onRepeatingRequestError(lastFrameNumber);
1019 }
1020
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001021 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001022 mStreamingRequestId = REQUEST_ID_NONE;
1023}
1024
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001025void CameraDeviceClient::notifyIdle() {
1026 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001027 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001028
1029 if (remoteCb != 0) {
1030 remoteCb->onDeviceIdle();
1031 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07001032 Camera2ClientBase::notifyIdle();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001033}
1034
Jianing Weicb0652e2014-03-12 18:29:36 -07001035void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001036 nsecs_t timestamp) {
1037 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001038 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001039 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07001040 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001041 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07001042 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001043}
1044
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001045void CameraDeviceClient::notifyPrepared(int streamId) {
1046 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001047 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001048 if (remoteCb != 0) {
1049 remoteCb->onPrepared(streamId);
1050 }
1051}
1052
Igor Murashkine7ee7632013-06-11 18:10:18 -07001053void CameraDeviceClient::detachDevice() {
1054 if (mDevice == 0) return;
1055
1056 ALOGV("Camera %d: Stopping processors", mCameraId);
1057
1058 mFrameProcessor->removeListener(FRAME_PROCESSOR_LISTENER_MIN_ID,
1059 FRAME_PROCESSOR_LISTENER_MAX_ID,
1060 /*listener*/this);
1061 mFrameProcessor->requestExit();
1062 ALOGV("Camera %d: Waiting for threads", mCameraId);
1063 mFrameProcessor->join();
1064 ALOGV("Camera %d: Disconnecting device", mCameraId);
1065
1066 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
1067 {
1068 mDevice->clearStreamingRequest();
1069
1070 status_t code;
1071 if ((code = mDevice->waitUntilDrained()) != OK) {
1072 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
1073 code);
1074 }
1075 }
1076
1077 Camera2ClientBase::detachDevice();
1078}
1079
1080/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07001081void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07001082 ATRACE_CALL();
1083 ALOGV("%s", __FUNCTION__);
1084
Igor Murashkin4fb55c12013-08-29 17:43:01 -07001085 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001086 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07001087 if (remoteCb != NULL) {
Jianing Weicb0652e2014-03-12 18:29:36 -07001088 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001089 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001090}
1091
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001092binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07001093 if (mDisconnected) {
1094 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
1095 "The camera device has been disconnected");
1096 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001097 status_t res = checkPid(checkLocation);
1098 return (res == OK) ? binder::Status::ok() :
1099 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
1100 "Attempt to use camera from a different process than original client");
1101}
1102
Igor Murashkine7ee7632013-06-11 18:10:18 -07001103// TODO: move to Camera2ClientBase
1104bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
1105
1106 const int pid = IPCThreadState::self()->getCallingPid();
1107 const int selfPid = getpid();
1108 camera_metadata_entry_t entry;
1109
1110 /**
1111 * Mixin default important security values
1112 * - android.led.transmit = defaulted ON
1113 */
1114 CameraMetadata staticInfo = mDevice->info();
1115 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
1116 for(size_t i = 0; i < entry.count; ++i) {
1117 uint8_t led = entry.data.u8[i];
1118
1119 switch(led) {
1120 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
1121 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
1122 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
1123 metadata.update(ANDROID_LED_TRANSMIT,
1124 &transmitDefault, 1);
1125 }
1126 break;
1127 }
1128 }
1129 }
1130
1131 // We can do anything!
1132 if (pid == selfPid) {
1133 return true;
1134 }
1135
1136 /**
1137 * Permission check special fields in the request
1138 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
1139 */
1140 entry = metadata.find(ANDROID_LED_TRANSMIT);
1141 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
1142 String16 permissionString =
1143 String16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
1144 if (!checkCallingPermission(permissionString)) {
1145 const int uid = IPCThreadState::self()->getCallingUid();
1146 ALOGE("Permission Denial: "
1147 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
1148 return false;
1149 }
1150 }
1151
1152 return true;
1153}
1154
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001155status_t CameraDeviceClient::getRotationTransformLocked(int32_t* transform) {
1156 ALOGV("%s: begin", __FUNCTION__);
1157
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001158 const CameraMetadata& staticInfo = mDevice->info();
Ruben Brunk5698d442014-06-18 10:39:40 -07001159 return CameraUtils::getRotationTransform(staticInfo, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001160}
1161
Igor Murashkine7ee7632013-06-11 18:10:18 -07001162} // namespace android