blob: 47321e0722ecd903cf10bb0c9ac7046d12e36dc6 [file] [log] [blame]
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001/*
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 "Camera3-Device"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
19//#define LOG_NDEBUG 0
20//#define LOG_NNDEBUG 0 // Per-frame verbose logging
21
22#ifdef LOG_NNDEBUG
23#define ALOGVV(...) ALOGV(__VA_ARGS__)
24#else
25#define ALOGVV(...) ((void)0)
26#endif
27
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -070028// Convenience macro for transient errors
29#define CLOGE(fmt, ...) ALOGE("Camera %d: %s: " fmt, mId, __FUNCTION__, \
30 ##__VA_ARGS__)
31
32// Convenience macros for transitioning to the error state
33#define SET_ERR(fmt, ...) setErrorState( \
34 "%s: " fmt, __FUNCTION__, \
35 ##__VA_ARGS__)
36#define SET_ERR_L(fmt, ...) setErrorStateLocked( \
37 "%s: " fmt, __FUNCTION__, \
38 ##__VA_ARGS__)
39
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080040#include <utils/Log.h>
41#include <utils/Trace.h>
42#include <utils/Timers.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070043
44#include "device3/Camera3Device.h"
45#include "device3/Camera3OutputStream.h"
46#include "device3/Camera3InputStream.h"
47#include "device3/Camera3ZslStream.h"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080048
49using namespace android::camera3;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080050
51namespace android {
52
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080053Camera3Device::Camera3Device(int id):
54 mId(id),
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080055 mHal3Device(NULL),
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -070056 mStatus(STATUS_UNINITIALIZED),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -070057 mNextResultFrameNumber(0),
58 mNextShutterFrameNumber(0),
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -070059 mListener(NULL)
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080060{
61 ATRACE_CALL();
62 camera3_callback_ops::notify = &sNotify;
63 camera3_callback_ops::process_capture_result = &sProcessCaptureResult;
64 ALOGV("%s: Created device for camera %d", __FUNCTION__, id);
65}
66
67Camera3Device::~Camera3Device()
68{
69 ATRACE_CALL();
70 ALOGV("%s: Tearing down for camera id %d", __FUNCTION__, mId);
71 disconnect();
72}
73
Igor Murashkin71381052013-03-04 14:53:08 -080074int Camera3Device::getId() const {
75 return mId;
76}
77
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080078/**
79 * CameraDeviceBase interface
80 */
81
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080082status_t Camera3Device::initialize(camera_module_t *module)
83{
84 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080085 Mutex::Autolock l(mLock);
86
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080087 ALOGV("%s: Initializing device for camera %d", __FUNCTION__, mId);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080088 if (mStatus != STATUS_UNINITIALIZED) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -070089 CLOGE("Already initialized!");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080090 return INVALID_OPERATION;
91 }
92
93 /** Open HAL device */
94
95 status_t res;
96 String8 deviceName = String8::format("%d", mId);
97
98 camera3_device_t *device;
99
100 res = module->common.methods->open(&module->common, deviceName.string(),
101 reinterpret_cast<hw_device_t**>(&device));
102
103 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700104 SET_ERR_L("Could not open camera: %s (%d)", strerror(-res), res);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800105 return res;
106 }
107
108 /** Cross-check device version */
109
110 if (device->common.version != CAMERA_DEVICE_API_VERSION_3_0) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700111 SET_ERR_L("Could not open camera: "
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800112 "Camera device is not version %x, reports %x instead",
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700113 CAMERA_DEVICE_API_VERSION_3_0,
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800114 device->common.version);
115 device->common.close(&device->common);
116 return BAD_VALUE;
117 }
118
119 camera_info info;
120 res = module->get_camera_info(mId, &info);
121 if (res != OK) return res;
122
123 if (info.device_version != device->common.version) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700124 SET_ERR_L("HAL reporting mismatched camera_info version (%x)"
125 " and device version (%x).",
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800126 device->common.version, info.device_version);
127 device->common.close(&device->common);
128 return BAD_VALUE;
129 }
130
131 /** Initialize device with callback functions */
132
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700133 ATRACE_BEGIN("camera3->initialize");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800134 res = device->ops->initialize(device, this);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700135 ATRACE_END();
136
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800137 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700138 SET_ERR_L("Unable to initialize HAL device: %s (%d)",
139 strerror(-res), res);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800140 device->common.close(&device->common);
141 return BAD_VALUE;
142 }
143
144 /** Get vendor metadata tags */
145
146 mVendorTagOps.get_camera_vendor_section_name = NULL;
147
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700148 ATRACE_BEGIN("camera3->get_metadata_vendor_tag_ops");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800149 device->ops->get_metadata_vendor_tag_ops(device, &mVendorTagOps);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700150 ATRACE_END();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800151
152 if (mVendorTagOps.get_camera_vendor_section_name != NULL) {
153 res = set_camera_metadata_vendor_tag_ops(&mVendorTagOps);
154 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700155 SET_ERR_L("Unable to set tag ops: %s (%d)",
156 strerror(-res), res);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800157 device->common.close(&device->common);
158 return res;
159 }
160 }
161
162 /** Start up request queue thread */
163
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800164 mRequestThread = new RequestThread(this, device);
165 res = mRequestThread->run(String8::format("C3Dev-%d-ReqQueue", mId).string());
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800166 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700167 SET_ERR_L("Unable to start request queue thread: %s (%d)",
168 strerror(-res), res);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800169 device->common.close(&device->common);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800170 mRequestThread.clear();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800171 return res;
172 }
173
174 /** Everything is good to go */
175
176 mDeviceInfo = info.static_camera_characteristics;
177 mHal3Device = device;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800178 mStatus = STATUS_IDLE;
179 mNextStreamId = 0;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700180 mNeedConfig = true;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800181
182 return OK;
183}
184
185status_t Camera3Device::disconnect() {
186 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800187 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800188
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800189 ALOGV("%s: E", __FUNCTION__);
190
Eino-Ville Talvala214a17f2013-06-13 12:20:02 -0700191 status_t res = OK;
192 if (mStatus == STATUS_UNINITIALIZED) return res;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800193
194 if (mStatus == STATUS_ACTIVE ||
195 (mStatus == STATUS_ERROR && mRequestThread != NULL)) {
196 res = mRequestThread->clearRepeatingRequests();
197 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700198 SET_ERR_L("Can't stop streaming");
Eino-Ville Talvala214a17f2013-06-13 12:20:02 -0700199 // Continue to close device even in case of error
200 } else {
201 res = waitUntilDrainedLocked();
202 if (res != OK) {
203 SET_ERR_L("Timeout waiting for HAL to drain");
204 // Continue to close device even in case of error
205 }
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800206 }
207 }
208 assert(mStatus == STATUS_IDLE || mStatus == STATUS_ERROR);
209
Eino-Ville Talvala214a17f2013-06-13 12:20:02 -0700210 if (mStatus == STATUS_ERROR) {
211 CLOGE("Shutting down in an error state");
212 }
213
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800214 if (mRequestThread != NULL) {
215 mRequestThread->requestExit();
216 }
217
218 mOutputStreams.clear();
219 mInputStream.clear();
220
221 if (mRequestThread != NULL) {
Eino-Ville Talvala214a17f2013-06-13 12:20:02 -0700222 if (mStatus != STATUS_ERROR) {
223 // HAL may be in a bad state, so waiting for request thread
224 // (which may be stuck in the HAL processCaptureRequest call)
225 // could be dangerous.
226 mRequestThread->join();
227 }
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800228 mRequestThread.clear();
229 }
230
231 if (mHal3Device != NULL) {
232 mHal3Device->common.close(&mHal3Device->common);
233 mHal3Device = NULL;
234 }
235
236 mStatus = STATUS_UNINITIALIZED;
237
238 ALOGV("%s: X", __FUNCTION__);
Eino-Ville Talvala214a17f2013-06-13 12:20:02 -0700239 return res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800240}
241
242status_t Camera3Device::dump(int fd, const Vector<String16> &args) {
243 ATRACE_CALL();
244 (void)args;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800245 String8 lines;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800246
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800247 const char *status =
248 mStatus == STATUS_ERROR ? "ERROR" :
249 mStatus == STATUS_UNINITIALIZED ? "UNINITIALIZED" :
250 mStatus == STATUS_IDLE ? "IDLE" :
251 mStatus == STATUS_ACTIVE ? "ACTIVE" :
252 "Unknown";
253 lines.appendFormat(" Device status: %s\n", status);
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700254 if (mStatus == STATUS_ERROR) {
255 lines.appendFormat(" Error cause: %s\n", mErrorCause.string());
256 }
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800257 lines.appendFormat(" Stream configuration:\n");
258
259 if (mInputStream != NULL) {
260 write(fd, lines.string(), lines.size());
261 mInputStream->dump(fd, args);
262 } else {
263 lines.appendFormat(" No input stream.\n");
264 write(fd, lines.string(), lines.size());
265 }
266 for (size_t i = 0; i < mOutputStreams.size(); i++) {
267 mOutputStreams[i]->dump(fd,args);
268 }
269
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700270 lines = String8(" In-flight requests:\n");
271 if (mInFlightMap.size() == 0) {
272 lines.append(" None\n");
273 } else {
274 for (size_t i = 0; i < mInFlightMap.size(); i++) {
275 InFlightRequest r = mInFlightMap.valueAt(i);
276 lines.appendFormat(" Frame %d | Timestamp: %lld, metadata"
277 " arrived: %s, buffers left: %d\n", mInFlightMap.keyAt(i),
278 r.captureTimestamp, r.haveResultMetadata ? "true" : "false",
279 r.numBuffersLeft);
280 }
281 }
282 write(fd, lines.string(), lines.size());
283
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800284 if (mHal3Device != NULL) {
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700285 lines = String8(" HAL device dump:\n");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800286 write(fd, lines.string(), lines.size());
287 mHal3Device->ops->dump(mHal3Device, fd);
288 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800289
290 return OK;
291}
292
293const CameraMetadata& Camera3Device::info() const {
294 ALOGVV("%s: E", __FUNCTION__);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800295 if (CC_UNLIKELY(mStatus == STATUS_UNINITIALIZED ||
296 mStatus == STATUS_ERROR)) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700297 ALOGW("%s: Access to static info %s!", __FUNCTION__,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800298 mStatus == STATUS_ERROR ?
299 "when in error state" : "before init");
300 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800301 return mDeviceInfo;
302}
303
304status_t Camera3Device::capture(CameraMetadata &request) {
305 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800306 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800307
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700308 // TODO: take ownership of the request
309
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800310 switch (mStatus) {
311 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700312 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800313 return INVALID_OPERATION;
314 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700315 CLOGE("Device not initialized");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800316 return INVALID_OPERATION;
317 case STATUS_IDLE:
318 case STATUS_ACTIVE:
319 // OK
320 break;
321 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700322 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800323 return INVALID_OPERATION;
324 }
325
326 sp<CaptureRequest> newRequest = setUpRequestLocked(request);
327 if (newRequest == NULL) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700328 CLOGE("Can't create capture request");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800329 return BAD_VALUE;
330 }
331
332 return mRequestThread->queueRequest(newRequest);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800333}
334
335
336status_t Camera3Device::setStreamingRequest(const CameraMetadata &request) {
337 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800338 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800339
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800340 switch (mStatus) {
341 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700342 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800343 return INVALID_OPERATION;
344 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700345 CLOGE("Device not initialized");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800346 return INVALID_OPERATION;
347 case STATUS_IDLE:
348 case STATUS_ACTIVE:
349 // OK
350 break;
351 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700352 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800353 return INVALID_OPERATION;
354 }
355
356 sp<CaptureRequest> newRepeatingRequest = setUpRequestLocked(request);
357 if (newRepeatingRequest == NULL) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700358 CLOGE("Can't create repeating request");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800359 return BAD_VALUE;
360 }
361
362 RequestList newRepeatingRequests;
363 newRepeatingRequests.push_back(newRepeatingRequest);
364
365 return mRequestThread->setRepeatingRequests(newRepeatingRequests);
366}
367
368
369sp<Camera3Device::CaptureRequest> Camera3Device::setUpRequestLocked(
370 const CameraMetadata &request) {
371 status_t res;
372
373 if (mStatus == STATUS_IDLE) {
374 res = configureStreamsLocked();
375 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700376 SET_ERR_L("Can't set up streams: %s (%d)", strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800377 return NULL;
378 }
379 }
380
381 sp<CaptureRequest> newRequest = createCaptureRequest(request);
382 return newRequest;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800383}
384
385status_t Camera3Device::clearStreamingRequest() {
386 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800387 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800388
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800389 switch (mStatus) {
390 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700391 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800392 return INVALID_OPERATION;
393 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700394 CLOGE("Device not initialized");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800395 return INVALID_OPERATION;
396 case STATUS_IDLE:
397 case STATUS_ACTIVE:
398 // OK
399 break;
400 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700401 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800402 return INVALID_OPERATION;
403 }
404
405 return mRequestThread->clearRepeatingRequests();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800406}
407
408status_t Camera3Device::waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) {
409 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800410
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700411 return mRequestThread->waitUntilRequestProcessed(requestId, timeout);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800412}
413
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700414status_t Camera3Device::createInputStream(
415 uint32_t width, uint32_t height, int format, int *id) {
416 ATRACE_CALL();
417 Mutex::Autolock l(mLock);
418
419 status_t res;
420 bool wasActive = false;
421
422 switch (mStatus) {
423 case STATUS_ERROR:
424 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
425 return INVALID_OPERATION;
426 case STATUS_UNINITIALIZED:
427 ALOGE("%s: Device not initialized", __FUNCTION__);
428 return INVALID_OPERATION;
429 case STATUS_IDLE:
430 // OK
431 break;
432 case STATUS_ACTIVE:
433 ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__);
434 mRequestThread->setPaused(true);
435 res = waitUntilDrainedLocked();
436 if (res != OK) {
437 ALOGE("%s: Can't pause captures to reconfigure streams!",
438 __FUNCTION__);
439 mStatus = STATUS_ERROR;
440 return res;
441 }
442 wasActive = true;
443 break;
444 default:
445 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
446 return INVALID_OPERATION;
447 }
448 assert(mStatus == STATUS_IDLE);
449
450 if (mInputStream != 0) {
451 ALOGE("%s: Cannot create more than 1 input stream", __FUNCTION__);
452 return INVALID_OPERATION;
453 }
454
455 sp<Camera3InputStream> newStream = new Camera3InputStream(mNextStreamId,
456 width, height, format);
457
458 mInputStream = newStream;
459
460 *id = mNextStreamId++;
461
462 // Continue captures if active at start
463 if (wasActive) {
464 ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__);
465 res = configureStreamsLocked();
466 if (res != OK) {
467 ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)",
468 __FUNCTION__, mNextStreamId, strerror(-res), res);
469 return res;
470 }
471 mRequestThread->setPaused(false);
472 }
473
474 return OK;
475}
476
Igor Murashkin2fba5842013-04-22 14:03:54 -0700477
478status_t Camera3Device::createZslStream(
479 uint32_t width, uint32_t height,
480 int depth,
481 /*out*/
482 int *id,
483 sp<Camera3ZslStream>* zslStream) {
484 ATRACE_CALL();
485 Mutex::Autolock l(mLock);
486
487 status_t res;
488 bool wasActive = false;
489
490 switch (mStatus) {
491 case STATUS_ERROR:
492 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
493 return INVALID_OPERATION;
494 case STATUS_UNINITIALIZED:
495 ALOGE("%s: Device not initialized", __FUNCTION__);
496 return INVALID_OPERATION;
497 case STATUS_IDLE:
498 // OK
499 break;
500 case STATUS_ACTIVE:
501 ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__);
502 mRequestThread->setPaused(true);
503 res = waitUntilDrainedLocked();
504 if (res != OK) {
505 ALOGE("%s: Can't pause captures to reconfigure streams!",
506 __FUNCTION__);
507 mStatus = STATUS_ERROR;
508 return res;
509 }
510 wasActive = true;
511 break;
512 default:
513 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
514 return INVALID_OPERATION;
515 }
516 assert(mStatus == STATUS_IDLE);
517
518 if (mInputStream != 0) {
519 ALOGE("%s: Cannot create more than 1 input stream", __FUNCTION__);
520 return INVALID_OPERATION;
521 }
522
523 sp<Camera3ZslStream> newStream = new Camera3ZslStream(mNextStreamId,
524 width, height, depth);
525
526 res = mOutputStreams.add(mNextStreamId, newStream);
527 if (res < 0) {
528 ALOGE("%s: Can't add new stream to set: %s (%d)",
529 __FUNCTION__, strerror(-res), res);
530 return res;
531 }
532 mInputStream = newStream;
533
534 *id = mNextStreamId++;
535 *zslStream = newStream;
536
537 // Continue captures if active at start
538 if (wasActive) {
539 ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__);
540 res = configureStreamsLocked();
541 if (res != OK) {
542 ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)",
543 __FUNCTION__, mNextStreamId, strerror(-res), res);
544 return res;
545 }
546 mRequestThread->setPaused(false);
547 }
548
549 return OK;
550}
551
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800552status_t Camera3Device::createStream(sp<ANativeWindow> consumer,
553 uint32_t width, uint32_t height, int format, size_t size, int *id) {
554 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800555 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800556
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800557 status_t res;
558 bool wasActive = false;
559
560 switch (mStatus) {
561 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700562 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800563 return INVALID_OPERATION;
564 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700565 CLOGE("Device not initialized");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800566 return INVALID_OPERATION;
567 case STATUS_IDLE:
568 // OK
569 break;
570 case STATUS_ACTIVE:
571 ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__);
572 mRequestThread->setPaused(true);
573 res = waitUntilDrainedLocked();
574 if (res != OK) {
575 ALOGE("%s: Can't pause captures to reconfigure streams!",
576 __FUNCTION__);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800577 return res;
578 }
579 wasActive = true;
580 break;
581 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700582 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800583 return INVALID_OPERATION;
584 }
585 assert(mStatus == STATUS_IDLE);
586
587 sp<Camera3OutputStream> newStream;
588 if (format == HAL_PIXEL_FORMAT_BLOB) {
589 newStream = new Camera3OutputStream(mNextStreamId, consumer,
590 width, height, size, format);
591 } else {
592 newStream = new Camera3OutputStream(mNextStreamId, consumer,
593 width, height, format);
594 }
595
596 res = mOutputStreams.add(mNextStreamId, newStream);
597 if (res < 0) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700598 SET_ERR_L("Can't add new stream to set: %s (%d)", strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800599 return res;
600 }
601
602 *id = mNextStreamId++;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700603 mNeedConfig = true;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800604
605 // Continue captures if active at start
606 if (wasActive) {
607 ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__);
608 res = configureStreamsLocked();
609 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700610 CLOGE("Can't reconfigure device for new stream %d: %s (%d)",
611 mNextStreamId, strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800612 return res;
613 }
614 mRequestThread->setPaused(false);
615 }
616
617 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800618}
619
620status_t Camera3Device::createReprocessStreamFromStream(int outputId, int *id) {
621 ATRACE_CALL();
622 (void)outputId; (void)id;
623
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700624 CLOGE("Unimplemented");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800625 return INVALID_OPERATION;
626}
627
628
629status_t Camera3Device::getStreamInfo(int id,
630 uint32_t *width, uint32_t *height, uint32_t *format) {
631 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800632 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800633
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800634 switch (mStatus) {
635 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700636 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800637 return INVALID_OPERATION;
638 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700639 CLOGE("Device not initialized!");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800640 return INVALID_OPERATION;
641 case STATUS_IDLE:
642 case STATUS_ACTIVE:
643 // OK
644 break;
645 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700646 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800647 return INVALID_OPERATION;
648 }
649
650 ssize_t idx = mOutputStreams.indexOfKey(id);
651 if (idx == NAME_NOT_FOUND) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700652 CLOGE("Stream %d is unknown", id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800653 return idx;
654 }
655
656 if (width) *width = mOutputStreams[idx]->getWidth();
657 if (height) *height = mOutputStreams[idx]->getHeight();
658 if (format) *format = mOutputStreams[idx]->getFormat();
659
660 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800661}
662
663status_t Camera3Device::setStreamTransform(int id,
664 int transform) {
665 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800666 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800667
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800668 switch (mStatus) {
669 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700670 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800671 return INVALID_OPERATION;
672 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700673 CLOGE("Device not initialized");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800674 return INVALID_OPERATION;
675 case STATUS_IDLE:
676 case STATUS_ACTIVE:
677 // OK
678 break;
679 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700680 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800681 return INVALID_OPERATION;
682 }
683
684 ssize_t idx = mOutputStreams.indexOfKey(id);
685 if (idx == NAME_NOT_FOUND) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700686 CLOGE("Stream %d does not exist",
687 id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800688 return BAD_VALUE;
689 }
690
691 return mOutputStreams.editValueAt(idx)->setTransform(transform);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800692}
693
694status_t Camera3Device::deleteStream(int id) {
695 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800696 Mutex::Autolock l(mLock);
697 status_t res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800698
Igor Murashkine2172be2013-05-28 15:31:39 -0700699 ALOGV("%s: Camera %d: Deleting stream %d", __FUNCTION__, mId, id);
700
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800701 // CameraDevice semantics require device to already be idle before
702 // deleteStream is called, unlike for createStream.
703 if (mStatus != STATUS_IDLE) {
Igor Murashkin52827132013-05-13 14:53:44 -0700704 ALOGV("%s: Camera %d: Device not idle", __FUNCTION__, mId);
705 return -EBUSY;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800706 }
707
Igor Murashkin2fba5842013-04-22 14:03:54 -0700708 sp<Camera3StreamInterface> deletedStream;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800709 if (mInputStream != NULL && id == mInputStream->getId()) {
710 deletedStream = mInputStream;
711 mInputStream.clear();
712 } else {
713 ssize_t idx = mOutputStreams.indexOfKey(id);
714 if (idx == NAME_NOT_FOUND) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700715 CLOGE("Stream %d does not exist", id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800716 return BAD_VALUE;
717 }
718 deletedStream = mOutputStreams.editValueAt(idx);
719 mOutputStreams.removeItem(id);
720 }
721
722 // Free up the stream endpoint so that it can be used by some other stream
723 res = deletedStream->disconnect();
724 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700725 SET_ERR_L("Can't disconnect deleted stream %d", id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800726 // fall through since we want to still list the stream as deleted.
727 }
728 mDeletedStreams.add(deletedStream);
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700729 mNeedConfig = true;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800730
731 return res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800732}
733
734status_t Camera3Device::deleteReprocessStream(int id) {
735 ATRACE_CALL();
736 (void)id;
737
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700738 CLOGE("Unimplemented");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800739 return INVALID_OPERATION;
740}
741
742
743status_t Camera3Device::createDefaultRequest(int templateId,
744 CameraMetadata *request) {
745 ATRACE_CALL();
Alex Rayfe7e0c62013-05-30 00:12:13 -0700746 ALOGV("%s: for template %d", __FUNCTION__, templateId);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800747 Mutex::Autolock l(mLock);
748
749 switch (mStatus) {
750 case STATUS_ERROR:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700751 CLOGE("Device has encountered a serious error");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800752 return INVALID_OPERATION;
753 case STATUS_UNINITIALIZED:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700754 CLOGE("Device is not initialized!");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800755 return INVALID_OPERATION;
756 case STATUS_IDLE:
757 case STATUS_ACTIVE:
758 // OK
759 break;
760 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700761 SET_ERR_L("Unexpected status: %d", mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800762 return INVALID_OPERATION;
763 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800764
765 const camera_metadata_t *rawRequest;
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700766 ATRACE_BEGIN("camera3->construct_default_request_settings");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800767 rawRequest = mHal3Device->ops->construct_default_request_settings(
768 mHal3Device, templateId);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700769 ATRACE_END();
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700770 if (rawRequest == NULL) {
771 SET_ERR_L("HAL is unable to construct default settings for template %d",
772 templateId);
773 return DEAD_OBJECT;
774 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800775 *request = rawRequest;
776
777 return OK;
778}
779
780status_t Camera3Device::waitUntilDrained() {
781 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800782 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800783
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800784 return waitUntilDrainedLocked();
785}
786
787status_t Camera3Device::waitUntilDrainedLocked() {
788 ATRACE_CALL();
789 status_t res;
790
791 switch (mStatus) {
792 case STATUS_UNINITIALIZED:
793 case STATUS_IDLE:
794 ALOGV("%s: Already idle", __FUNCTION__);
795 return OK;
796 case STATUS_ERROR:
797 case STATUS_ACTIVE:
798 // Need to shut down
799 break;
800 default:
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700801 SET_ERR_L("Unexpected status: %d",mStatus);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800802 return INVALID_OPERATION;
803 }
804
805 if (mRequestThread != NULL) {
806 res = mRequestThread->waitUntilPaused(kShutdownTimeout);
807 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700808 SET_ERR_L("Can't stop request thread in %f seconds!",
809 kShutdownTimeout/1e9);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800810 return res;
811 }
812 }
813 if (mInputStream != NULL) {
814 res = mInputStream->waitUntilIdle(kShutdownTimeout);
815 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700816 SET_ERR_L("Can't idle input stream %d in %f seconds!",
817 mInputStream->getId(), kShutdownTimeout/1e9);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800818 return res;
819 }
820 }
821 for (size_t i = 0; i < mOutputStreams.size(); i++) {
822 res = mOutputStreams.editValueAt(i)->waitUntilIdle(kShutdownTimeout);
823 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700824 SET_ERR_L("Can't idle output stream %d in %f seconds!",
825 mOutputStreams.keyAt(i), kShutdownTimeout/1e9);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800826 return res;
827 }
828 }
829
830 if (mStatus != STATUS_ERROR) {
831 mStatus = STATUS_IDLE;
832 }
833
834 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800835}
836
837status_t Camera3Device::setNotifyCallback(NotificationListener *listener) {
838 ATRACE_CALL();
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700839 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800840
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700841 if (listener != NULL && mListener != NULL) {
842 ALOGW("%s: Replacing old callback listener", __FUNCTION__);
843 }
844 mListener = listener;
845
846 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800847}
848
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700849bool Camera3Device::willNotify3A() {
850 return false;
851}
852
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800853status_t Camera3Device::waitForNextFrame(nsecs_t timeout) {
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700854 ATRACE_CALL();
855 status_t res;
856 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800857
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700858 while (mResultQueue.empty()) {
859 res = mResultSignal.waitRelative(mOutputLock, timeout);
860 if (res == TIMED_OUT) {
861 return res;
862 } else if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700863 ALOGW("%s: Camera %d: No frame in %lld ns: %s (%d)",
864 __FUNCTION__, mId, timeout, strerror(-res), res);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700865 return res;
866 }
867 }
868 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800869}
870
871status_t Camera3Device::getNextFrame(CameraMetadata *frame) {
872 ATRACE_CALL();
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700873 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800874
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700875 if (mResultQueue.empty()) {
876 return NOT_ENOUGH_DATA;
877 }
878
879 CameraMetadata &result = *(mResultQueue.begin());
880 frame->acquire(result);
881 mResultQueue.erase(mResultQueue.begin());
882
883 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800884}
885
886status_t Camera3Device::triggerAutofocus(uint32_t id) {
887 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800888
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700889 ALOGV("%s: Triggering autofocus, id %d", __FUNCTION__, id);
890 // Mix-in this trigger into the next request and only the next request.
891 RequestTrigger trigger[] = {
892 {
893 ANDROID_CONTROL_AF_TRIGGER,
894 ANDROID_CONTROL_AF_TRIGGER_START
895 },
896 {
897 ANDROID_CONTROL_AF_TRIGGER_ID,
898 static_cast<int32_t>(id)
899 },
900 };
901
902 return mRequestThread->queueTrigger(trigger,
903 sizeof(trigger)/sizeof(trigger[0]));
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800904}
905
906status_t Camera3Device::triggerCancelAutofocus(uint32_t id) {
907 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800908
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700909 ALOGV("%s: Triggering cancel autofocus, id %d", __FUNCTION__, id);
910 // Mix-in this trigger into the next request and only the next request.
911 RequestTrigger trigger[] = {
912 {
913 ANDROID_CONTROL_AF_TRIGGER,
914 ANDROID_CONTROL_AF_TRIGGER_CANCEL
915 },
916 {
917 ANDROID_CONTROL_AF_TRIGGER_ID,
918 static_cast<int32_t>(id)
919 },
920 };
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800921
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700922 return mRequestThread->queueTrigger(trigger,
923 sizeof(trigger)/sizeof(trigger[0]));
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800924}
925
926status_t Camera3Device::triggerPrecaptureMetering(uint32_t id) {
927 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800928
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700929 ALOGV("%s: Triggering precapture metering, id %d", __FUNCTION__, id);
930 // Mix-in this trigger into the next request and only the next request.
931 RequestTrigger trigger[] = {
932 {
933 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER,
934 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_START
935 },
936 {
937 ANDROID_CONTROL_AE_PRECAPTURE_ID,
938 static_cast<int32_t>(id)
939 },
940 };
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800941
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700942 return mRequestThread->queueTrigger(trigger,
943 sizeof(trigger)/sizeof(trigger[0]));
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800944}
945
946status_t Camera3Device::pushReprocessBuffer(int reprocessStreamId,
947 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) {
948 ATRACE_CALL();
949 (void)reprocessStreamId; (void)buffer; (void)listener;
950
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700951 CLOGE("Unimplemented");
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800952 return INVALID_OPERATION;
953}
954
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700955status_t Camera3Device::flush() {
956 ATRACE_CALL();
957 ALOGV("%s: Camera %d: Flushing all requests", __FUNCTION__, mId);
958
959 Mutex::Autolock l(mLock);
960
961 mRequestThread->clear();
962 return mHal3Device->ops->flush(mHal3Device);
963}
964
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800965/**
966 * Camera3Device private methods
967 */
968
969sp<Camera3Device::CaptureRequest> Camera3Device::createCaptureRequest(
970 const CameraMetadata &request) {
971 ATRACE_CALL();
972 status_t res;
973
974 sp<CaptureRequest> newRequest = new CaptureRequest;
975 newRequest->mSettings = request;
976
977 camera_metadata_entry_t inputStreams =
978 newRequest->mSettings.find(ANDROID_REQUEST_INPUT_STREAMS);
979 if (inputStreams.count > 0) {
980 if (mInputStream == NULL ||
981 mInputStream->getId() != inputStreams.data.u8[0]) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700982 CLOGE("Request references unknown input stream %d",
983 inputStreams.data.u8[0]);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800984 return NULL;
985 }
986 // Lazy completion of stream configuration (allocation/registration)
987 // on first use
988 if (mInputStream->isConfiguring()) {
989 res = mInputStream->finishConfiguration(mHal3Device);
990 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700991 SET_ERR_L("Unable to finish configuring input stream %d:"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800992 " %s (%d)",
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700993 mInputStream->getId(), strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800994 return NULL;
995 }
996 }
997
998 newRequest->mInputStream = mInputStream;
999 newRequest->mSettings.erase(ANDROID_REQUEST_INPUT_STREAMS);
1000 }
1001
1002 camera_metadata_entry_t streams =
1003 newRequest->mSettings.find(ANDROID_REQUEST_OUTPUT_STREAMS);
1004 if (streams.count == 0) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001005 CLOGE("Zero output streams specified!");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001006 return NULL;
1007 }
1008
1009 for (size_t i = 0; i < streams.count; i++) {
1010 int idx = mOutputStreams.indexOfKey(streams.data.u8[i]);
1011 if (idx == NAME_NOT_FOUND) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001012 CLOGE("Request references unknown stream %d",
1013 streams.data.u8[i]);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001014 return NULL;
1015 }
Igor Murashkin2fba5842013-04-22 14:03:54 -07001016 sp<Camera3OutputStreamInterface> stream =
1017 mOutputStreams.editValueAt(idx);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001018
1019 // Lazy completion of stream configuration (allocation/registration)
1020 // on first use
1021 if (stream->isConfiguring()) {
1022 res = stream->finishConfiguration(mHal3Device);
1023 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001024 SET_ERR_L("Unable to finish configuring stream %d: %s (%d)",
1025 stream->getId(), strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001026 return NULL;
1027 }
1028 }
1029
1030 newRequest->mOutputStreams.push(stream);
1031 }
1032 newRequest->mSettings.erase(ANDROID_REQUEST_OUTPUT_STREAMS);
1033
1034 return newRequest;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001035}
1036
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001037status_t Camera3Device::configureStreamsLocked() {
1038 ATRACE_CALL();
1039 status_t res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001040
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001041 if (mStatus != STATUS_IDLE) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001042 CLOGE("Not idle");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001043 return INVALID_OPERATION;
1044 }
1045
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -07001046 if (!mNeedConfig) {
1047 ALOGV("%s: Skipping config, no stream changes", __FUNCTION__);
Eino-Ville Talvala31fdb292013-06-12 17:06:41 -07001048 mStatus = STATUS_ACTIVE;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -07001049 return OK;
1050 }
1051
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001052 // Start configuring the streams
1053
1054 camera3_stream_configuration config;
1055
1056 config.num_streams = (mInputStream != NULL) + mOutputStreams.size();
1057
1058 Vector<camera3_stream_t*> streams;
1059 streams.setCapacity(config.num_streams);
1060
1061 if (mInputStream != NULL) {
1062 camera3_stream_t *inputStream;
1063 inputStream = mInputStream->startConfiguration();
1064 if (inputStream == NULL) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001065 SET_ERR_L("Can't start input stream configuration");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001066 return INVALID_OPERATION;
1067 }
1068 streams.add(inputStream);
1069 }
1070
1071 for (size_t i = 0; i < mOutputStreams.size(); i++) {
Igor Murashkin2fba5842013-04-22 14:03:54 -07001072
1073 // Don't configure bidi streams twice, nor add them twice to the list
1074 if (mOutputStreams[i].get() ==
1075 static_cast<Camera3StreamInterface*>(mInputStream.get())) {
1076
1077 config.num_streams--;
1078 continue;
1079 }
1080
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001081 camera3_stream_t *outputStream;
1082 outputStream = mOutputStreams.editValueAt(i)->startConfiguration();
1083 if (outputStream == NULL) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001084 SET_ERR_L("Can't start output stream configuration");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001085 return INVALID_OPERATION;
1086 }
1087 streams.add(outputStream);
1088 }
1089
1090 config.streams = streams.editArray();
1091
1092 // Do the HAL configuration; will potentially touch stream
1093 // max_buffers, usage, priv fields.
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001094 ATRACE_BEGIN("camera3->configure_streams");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001095 res = mHal3Device->ops->configure_streams(mHal3Device, &config);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001096 ATRACE_END();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001097
1098 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001099 SET_ERR_L("Unable to configure streams with HAL: %s (%d)",
1100 strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001101 return res;
1102 }
1103
Eino-Ville Talvala4c956762013-04-19 17:26:13 -07001104 // Finish all stream configuration immediately.
1105 // TODO: Try to relax this later back to lazy completion, which should be
1106 // faster
1107
Igor Murashkin073f8572013-05-02 14:59:28 -07001108 if (mInputStream != NULL && mInputStream->isConfiguring()) {
Eino-Ville Talvala4c956762013-04-19 17:26:13 -07001109 res = mInputStream->finishConfiguration(mHal3Device);
1110 if (res != OK) {
1111 SET_ERR_L("Can't finish configuring input stream %d: %s (%d)",
1112 mInputStream->getId(), strerror(-res), res);
1113 return res;
1114 }
1115 }
1116
1117 for (size_t i = 0; i < mOutputStreams.size(); i++) {
Igor Murashkin073f8572013-05-02 14:59:28 -07001118 sp<Camera3OutputStreamInterface> outputStream =
1119 mOutputStreams.editValueAt(i);
1120 if (outputStream->isConfiguring()) {
1121 res = outputStream->finishConfiguration(mHal3Device);
1122 if (res != OK) {
1123 SET_ERR_L("Can't finish configuring output stream %d: %s (%d)",
1124 outputStream->getId(), strerror(-res), res);
1125 return res;
1126 }
Eino-Ville Talvala4c956762013-04-19 17:26:13 -07001127 }
1128 }
1129
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001130 // Request thread needs to know to avoid using repeat-last-settings protocol
1131 // across configure_streams() calls
1132 mRequestThread->configurationComplete();
1133
1134 // Finish configuring the streams lazily on first reference
1135
1136 mStatus = STATUS_ACTIVE;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -07001137 mNeedConfig = false;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001138
1139 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001140}
1141
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001142void Camera3Device::setErrorState(const char *fmt, ...) {
1143 Mutex::Autolock l(mLock);
1144 va_list args;
1145 va_start(args, fmt);
1146
1147 setErrorStateLockedV(fmt, args);
1148
1149 va_end(args);
1150}
1151
1152void Camera3Device::setErrorStateV(const char *fmt, va_list args) {
1153 Mutex::Autolock l(mLock);
1154 setErrorStateLockedV(fmt, args);
1155}
1156
1157void Camera3Device::setErrorStateLocked(const char *fmt, ...) {
1158 va_list args;
1159 va_start(args, fmt);
1160
1161 setErrorStateLockedV(fmt, args);
1162
1163 va_end(args);
1164}
1165
1166void Camera3Device::setErrorStateLockedV(const char *fmt, va_list args) {
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001167 // Print out all error messages to log
1168 String8 errorCause = String8::formatV(fmt, args);
1169 ALOGE("Camera %d: %s", mId, errorCause.string());
1170
1171 // But only do error state transition steps for the first error
Zhijun Heb05eeae2013-06-06 13:51:22 -07001172 if (mStatus == STATUS_ERROR || mStatus == STATUS_UNINITIALIZED) return;
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001173
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001174 mErrorCause = errorCause;
1175
1176 mRequestThread->setPaused(true);
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001177 mStatus = STATUS_ERROR;
1178}
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001179
1180/**
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001181 * In-flight request management
1182 */
1183
1184status_t Camera3Device::registerInFlight(int32_t frameNumber,
1185 int32_t numBuffers) {
1186 ATRACE_CALL();
1187 Mutex::Autolock l(mInFlightLock);
1188
1189 ssize_t res;
1190 res = mInFlightMap.add(frameNumber, InFlightRequest(numBuffers));
1191 if (res < 0) return res;
1192
1193 return OK;
1194}
1195
1196/**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001197 * Camera HAL device callback methods
1198 */
1199
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001200void Camera3Device::processCaptureResult(const camera3_capture_result *result) {
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001201 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001202
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001203 status_t res;
1204
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001205 uint32_t frameNumber = result->frame_number;
1206 if (result->result == NULL && result->num_output_buffers == 0) {
1207 SET_ERR("No result data provided by HAL for frame %d",
1208 frameNumber);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001209 return;
1210 }
1211
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001212 // Get capture timestamp from list of in-flight requests, where it was added
1213 // by the shutter notification for this frame. Then update the in-flight
1214 // status and remove the in-flight entry if all result data has been
1215 // received.
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001216 nsecs_t timestamp = 0;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001217 {
1218 Mutex::Autolock l(mInFlightLock);
1219 ssize_t idx = mInFlightMap.indexOfKey(frameNumber);
1220 if (idx == NAME_NOT_FOUND) {
1221 SET_ERR("Unknown frame number for capture result: %d",
1222 frameNumber);
1223 return;
1224 }
1225 InFlightRequest &request = mInFlightMap.editValueAt(idx);
1226 timestamp = request.captureTimestamp;
1227 if (timestamp == 0) {
1228 SET_ERR("Called before shutter notify for frame %d",
1229 frameNumber);
1230 return;
1231 }
1232
1233 if (result->result != NULL) {
1234 if (request.haveResultMetadata) {
1235 SET_ERR("Called multiple times with metadata for frame %d",
1236 frameNumber);
1237 return;
1238 }
1239 request.haveResultMetadata = true;
1240 }
1241
1242 request.numBuffersLeft -= result->num_output_buffers;
1243
1244 if (request.numBuffersLeft < 0) {
1245 SET_ERR("Too many buffers returned for frame %d",
1246 frameNumber);
1247 return;
1248 }
1249
1250 if (request.haveResultMetadata && request.numBuffersLeft == 0) {
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001251 ATRACE_ASYNC_END("frame capture", frameNumber);
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001252 mInFlightMap.removeItemsAt(idx, 1);
1253 }
1254
1255 // Sanity check - if we have too many in-flight frames, something has
1256 // likely gone wrong
1257 if (mInFlightMap.size() > kInFlightWarnLimit) {
1258 CLOGE("In-flight list too large: %d", mInFlightMap.size());
1259 }
1260
1261 }
1262
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001263 // Process the result metadata, if provided
1264 if (result->result != NULL) {
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001265 Mutex::Autolock l(mOutputLock);
1266
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001267 if (frameNumber != mNextResultFrameNumber) {
1268 SET_ERR("Out-of-order capture result metadata submitted! "
1269 "(got frame number %d, expecting %d)",
1270 frameNumber, mNextResultFrameNumber);
1271 return;
1272 }
1273 mNextResultFrameNumber++;
1274
1275 CameraMetadata &captureResult =
1276 *mResultQueue.insert(mResultQueue.end(), CameraMetadata());
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001277
1278 captureResult = result->result;
Igor Murashkind2c90692013-04-02 12:32:32 -07001279 if (captureResult.update(ANDROID_REQUEST_FRAME_COUNT,
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001280 (int32_t*)&frameNumber, 1) != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001281 SET_ERR("Failed to set frame# in metadata (%d)",
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001282 frameNumber);
Igor Murashkind2c90692013-04-02 12:32:32 -07001283 } else {
1284 ALOGVV("%s: Camera %d: Set frame# in metadata (%d)",
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001285 __FUNCTION__, mId, frameNumber);
Igor Murashkind2c90692013-04-02 12:32:32 -07001286 }
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001287
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001288 // Check that there's a timestamp in the result metadata
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001289
1290 camera_metadata_entry entry =
1291 captureResult.find(ANDROID_SENSOR_TIMESTAMP);
1292 if (entry.count == 0) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001293 SET_ERR("No timestamp provided by HAL for frame %d!",
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001294 frameNumber);
Alex Rayfe7e0c62013-05-30 00:12:13 -07001295 } else if (timestamp != entry.data.i64[0]) {
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001296 SET_ERR("Timestamp mismatch between shutter notify and result"
1297 " metadata for frame %d (%lld vs %lld respectively)",
1298 frameNumber, timestamp, entry.data.i64[0]);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001299 }
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001300 } // scope for mOutputLock
1301
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001302 // Return completed buffers to their streams with the timestamp
1303
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001304 for (size_t i = 0; i < result->num_output_buffers; i++) {
1305 Camera3Stream *stream =
1306 Camera3Stream::cast(result->output_buffers[i].stream);
1307 res = stream->returnBuffer(result->output_buffers[i], timestamp);
1308 // Note: stream may be deallocated at this point, if this buffer was the
1309 // last reference to it.
1310 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001311 SET_ERR("Can't return buffer %d for frame %d to its stream: "
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001312 " %s (%d)", i, frameNumber, strerror(-res), res);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001313 }
1314 }
1315
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -07001316 // Finally, signal any waiters for new frames
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001317
Igor Murashkin4345d5b2013-05-17 14:39:53 -07001318 if (result->result != NULL) {
1319 mResultSignal.signal();
1320 }
1321
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001322}
1323
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -07001324
1325
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001326void Camera3Device::notify(const camera3_notify_msg *msg) {
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001327 ATRACE_CALL();
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001328 NotificationListener *listener;
1329 {
1330 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001331 listener = mListener;
1332 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001333
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001334 if (msg == NULL) {
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001335 SET_ERR("HAL sent NULL notify message!");
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001336 return;
1337 }
1338
1339 switch (msg->type) {
1340 case CAMERA3_MSG_ERROR: {
1341 int streamId = 0;
1342 if (msg->message.error.error_stream != NULL) {
1343 Camera3Stream *stream =
1344 Camera3Stream::cast(
1345 msg->message.error.error_stream);
1346 streamId = stream->getId();
1347 }
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001348 ALOGV("Camera %d: %s: HAL error, frame %d, stream %d: %d",
1349 mId, __FUNCTION__, msg->message.error.frame_number,
1350 streamId, msg->message.error.error_code);
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001351 if (listener != NULL) {
1352 listener->notifyError(msg->message.error.error_code,
1353 msg->message.error.frame_number, streamId);
1354 }
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001355 break;
1356 }
1357 case CAMERA3_MSG_SHUTTER: {
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001358 ssize_t idx;
1359 uint32_t frameNumber = msg->message.shutter.frame_number;
1360 nsecs_t timestamp = msg->message.shutter.timestamp;
1361 // Verify ordering of shutter notifications
1362 {
1363 Mutex::Autolock l(mOutputLock);
1364 if (frameNumber != mNextShutterFrameNumber) {
1365 SET_ERR("Shutter notification out-of-order. Expected "
1366 "notification for frame %d, got frame %d",
1367 mNextShutterFrameNumber, frameNumber);
1368 break;
1369 }
1370 mNextShutterFrameNumber++;
1371 }
1372
1373 // Set timestamp for the request in the in-flight tracking
1374 {
1375 Mutex::Autolock l(mInFlightLock);
1376 idx = mInFlightMap.indexOfKey(frameNumber);
1377 if (idx >= 0) {
1378 mInFlightMap.editValueAt(idx).captureTimestamp = timestamp;
1379 }
1380 }
1381 if (idx < 0) {
1382 SET_ERR("Shutter notification for non-existent frame number %d",
1383 frameNumber);
1384 break;
1385 }
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001386 ALOGVV("Camera %d: %s: Shutter fired for frame %d at %lld",
1387 mId, __FUNCTION__, frameNumber, timestamp);
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001388 // Call listener, if any
1389 if (listener != NULL) {
1390 listener->notifyShutter(frameNumber, timestamp);
1391 }
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001392 break;
1393 }
1394 default:
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001395 SET_ERR("Unknown notify message from HAL: %d",
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001396 msg->type);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001397 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001398}
1399
1400/**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001401 * RequestThread inner class methods
1402 */
1403
1404Camera3Device::RequestThread::RequestThread(wp<Camera3Device> parent,
1405 camera3_device_t *hal3Device) :
1406 Thread(false),
1407 mParent(parent),
1408 mHal3Device(hal3Device),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001409 mId(getId(parent)),
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001410 mReconfigured(false),
1411 mDoPause(false),
1412 mPaused(true),
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001413 mFrameNumber(0),
1414 mLatestRequestId(NAME_NOT_FOUND) {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001415}
1416
1417void Camera3Device::RequestThread::configurationComplete() {
1418 Mutex::Autolock l(mRequestLock);
1419 mReconfigured = true;
1420}
1421
1422status_t Camera3Device::RequestThread::queueRequest(
1423 sp<CaptureRequest> request) {
1424 Mutex::Autolock l(mRequestLock);
1425 mRequestQueue.push_back(request);
1426
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -07001427 unpauseForNewRequests();
1428
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001429 return OK;
1430}
1431
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001432
1433status_t Camera3Device::RequestThread::queueTrigger(
1434 RequestTrigger trigger[],
1435 size_t count) {
1436
1437 Mutex::Autolock l(mTriggerMutex);
1438 status_t ret;
1439
1440 for (size_t i = 0; i < count; ++i) {
1441 ret = queueTriggerLocked(trigger[i]);
1442
1443 if (ret != OK) {
1444 return ret;
1445 }
1446 }
1447
1448 return OK;
1449}
1450
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001451int Camera3Device::RequestThread::getId(const wp<Camera3Device> &device) {
1452 sp<Camera3Device> d = device.promote();
1453 if (d != NULL) return d->mId;
1454 return 0;
1455}
1456
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001457status_t Camera3Device::RequestThread::queueTriggerLocked(
1458 RequestTrigger trigger) {
1459
1460 uint32_t tag = trigger.metadataTag;
1461 ssize_t index = mTriggerMap.indexOfKey(tag);
1462
1463 switch (trigger.getTagType()) {
1464 case TYPE_BYTE:
1465 // fall-through
1466 case TYPE_INT32:
1467 break;
1468 default:
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001469 ALOGE("%s: Type not supported: 0x%x", __FUNCTION__,
1470 trigger.getTagType());
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001471 return INVALID_OPERATION;
1472 }
1473
1474 /**
1475 * Collect only the latest trigger, since we only have 1 field
1476 * in the request settings per trigger tag, and can't send more than 1
1477 * trigger per request.
1478 */
1479 if (index != NAME_NOT_FOUND) {
1480 mTriggerMap.editValueAt(index) = trigger;
1481 } else {
1482 mTriggerMap.add(tag, trigger);
1483 }
1484
1485 return OK;
1486}
1487
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001488status_t Camera3Device::RequestThread::setRepeatingRequests(
1489 const RequestList &requests) {
1490 Mutex::Autolock l(mRequestLock);
1491 mRepeatingRequests.clear();
1492 mRepeatingRequests.insert(mRepeatingRequests.begin(),
1493 requests.begin(), requests.end());
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -07001494
1495 unpauseForNewRequests();
1496
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001497 return OK;
1498}
1499
1500status_t Camera3Device::RequestThread::clearRepeatingRequests() {
1501 Mutex::Autolock l(mRequestLock);
1502 mRepeatingRequests.clear();
1503 return OK;
1504}
1505
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001506status_t Camera3Device::RequestThread::clear() {
1507 Mutex::Autolock l(mRequestLock);
1508 mRepeatingRequests.clear();
1509 mRequestQueue.clear();
1510 mTriggerMap.clear();
1511 return OK;
1512}
1513
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001514void Camera3Device::RequestThread::setPaused(bool paused) {
1515 Mutex::Autolock l(mPauseLock);
1516 mDoPause = paused;
1517 mDoPauseSignal.signal();
1518}
1519
1520status_t Camera3Device::RequestThread::waitUntilPaused(nsecs_t timeout) {
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001521 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001522 status_t res;
1523 Mutex::Autolock l(mPauseLock);
1524 while (!mPaused) {
1525 res = mPausedSignal.waitRelative(mPauseLock, timeout);
1526 if (res == TIMED_OUT) {
1527 return res;
1528 }
1529 }
1530 return OK;
1531}
1532
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001533status_t Camera3Device::RequestThread::waitUntilRequestProcessed(
1534 int32_t requestId, nsecs_t timeout) {
1535 Mutex::Autolock l(mLatestRequestMutex);
1536 status_t res;
1537 while (mLatestRequestId != requestId) {
1538 nsecs_t startTime = systemTime();
1539
1540 res = mLatestRequestSignal.waitRelative(mLatestRequestMutex, timeout);
1541 if (res != OK) return res;
1542
1543 timeout -= (systemTime() - startTime);
1544 }
1545
1546 return OK;
1547}
1548
1549
1550
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001551bool Camera3Device::RequestThread::threadLoop() {
1552
1553 status_t res;
1554
1555 // Handle paused state.
1556 if (waitIfPaused()) {
1557 return true;
1558 }
1559
1560 // Get work to do
1561
1562 sp<CaptureRequest> nextRequest = waitForNextRequest();
1563 if (nextRequest == NULL) {
1564 return true;
1565 }
1566
1567 // Create request to HAL
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001568 camera3_capture_request_t request = camera3_capture_request_t();
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001569 Vector<camera3_stream_buffer_t> outputBuffers;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001570
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001571 // Insert any queued triggers (before metadata is locked)
1572 int32_t triggerCount;
1573 res = insertTriggers(nextRequest);
1574 if (res < 0) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001575 SET_ERR("RequestThread: Unable to insert triggers "
1576 "(capture request %d, HAL device: %s (%d)",
1577 (mFrameNumber+1), strerror(-res), res);
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001578 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1579 return false;
1580 }
1581 triggerCount = res;
1582
1583 bool triggersMixedIn = (triggerCount > 0 || mPrevTriggers > 0);
1584
1585 // If the request is the same as last, or we had triggers last time
1586 if (mPrevRequest != nextRequest || triggersMixedIn) {
1587 /**
1588 * The request should be presorted so accesses in HAL
1589 * are O(logn). Sidenote, sorting a sorted metadata is nop.
1590 */
1591 nextRequest->mSettings.sort();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001592 request.settings = nextRequest->mSettings.getAndLock();
1593 mPrevRequest = nextRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001594 ALOGVV("%s: Request settings are NEW", __FUNCTION__);
1595
1596 IF_ALOGV() {
1597 camera_metadata_ro_entry_t e = camera_metadata_ro_entry_t();
1598 find_camera_metadata_ro_entry(
1599 request.settings,
1600 ANDROID_CONTROL_AF_TRIGGER,
1601 &e
1602 );
1603 if (e.count > 0) {
1604 ALOGV("%s: Request (frame num %d) had AF trigger 0x%x",
1605 __FUNCTION__,
1606 mFrameNumber+1,
1607 e.data.u8[0]);
1608 }
1609 }
1610 } else {
1611 // leave request.settings NULL to indicate 'reuse latest given'
1612 ALOGVV("%s: Request settings are REUSED",
1613 __FUNCTION__);
1614 }
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001615
1616 camera3_stream_buffer_t inputBuffer;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001617
1618 // Fill in buffers
1619
1620 if (nextRequest->mInputStream != NULL) {
1621 request.input_buffer = &inputBuffer;
Igor Murashkin5a269fa2013-04-15 14:59:22 -07001622 res = nextRequest->mInputStream->getInputBuffer(&inputBuffer);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001623 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001624 SET_ERR("RequestThread: Can't get input buffer, skipping request:"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001625 " %s (%d)", strerror(-res), res);
1626 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1627 return true;
1628 }
1629 } else {
1630 request.input_buffer = NULL;
1631 }
1632
1633 outputBuffers.insertAt(camera3_stream_buffer_t(), 0,
1634 nextRequest->mOutputStreams.size());
1635 request.output_buffers = outputBuffers.array();
1636 for (size_t i = 0; i < nextRequest->mOutputStreams.size(); i++) {
1637 res = nextRequest->mOutputStreams.editItemAt(i)->
1638 getBuffer(&outputBuffers.editItemAt(i));
1639 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001640 SET_ERR("RequestThread: Can't get output buffer, skipping request:"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001641 "%s (%d)", strerror(-res), res);
1642 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1643 return true;
1644 }
1645 request.num_output_buffers++;
1646 }
1647
1648 request.frame_number = mFrameNumber++;
1649
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001650 // Log request in the in-flight queue
1651 sp<Camera3Device> parent = mParent.promote();
1652 if (parent == NULL) {
1653 CLOGE("RequestThread: Parent is gone");
1654 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1655 return false;
1656 }
1657
1658 res = parent->registerInFlight(request.frame_number,
1659 request.num_output_buffers);
1660 if (res != OK) {
1661 SET_ERR("RequestThread: Unable to register new in-flight request:"
1662 " %s (%d)", strerror(-res), res);
1663 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1664 return false;
1665 }
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001666
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001667 // Submit request and block until ready for next one
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001668 ATRACE_ASYNC_BEGIN("frame capture", request.frame_number);
1669 ATRACE_BEGIN("camera3->process_capture_request");
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001670 res = mHal3Device->ops->process_capture_request(mHal3Device, &request);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -07001671 ATRACE_END();
1672
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001673 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001674 SET_ERR("RequestThread: Unable to submit capture request %d to HAL"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001675 " device: %s (%d)", request.frame_number, strerror(-res), res);
1676 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1677 return false;
1678 }
1679
1680 if (request.settings != NULL) {
1681 nextRequest->mSettings.unlock(request.settings);
1682 }
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001683
1684 // Remove any previously queued triggers (after unlock)
1685 res = removeTriggers(mPrevRequest);
1686 if (res != OK) {
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001687 SET_ERR("RequestThread: Unable to remove triggers "
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001688 "(capture request %d, HAL device: %s (%d)",
1689 request.frame_number, strerror(-res), res);
1690 return false;
1691 }
1692 mPrevTriggers = triggerCount;
1693
1694 // Read android.request.id from the request settings metadata
1695 // - inform waitUntilRequestProcessed thread of a new request ID
1696 {
1697 Mutex::Autolock al(mLatestRequestMutex);
1698
1699 camera_metadata_entry_t requestIdEntry =
1700 nextRequest->mSettings.find(ANDROID_REQUEST_ID);
1701 if (requestIdEntry.count > 0) {
1702 mLatestRequestId = requestIdEntry.data.i32[0];
1703 } else {
1704 ALOGW("%s: Did not have android.request.id set in the request",
1705 __FUNCTION__);
1706 mLatestRequestId = NAME_NOT_FOUND;
1707 }
1708
1709 mLatestRequestSignal.signal();
1710 }
1711
Igor Murashkin5a269fa2013-04-15 14:59:22 -07001712 // Return input buffer back to framework
1713 if (request.input_buffer != NULL) {
1714 Camera3Stream *stream =
1715 Camera3Stream::cast(request.input_buffer->stream);
1716 res = stream->returnInputBuffer(*(request.input_buffer));
1717 // Note: stream may be deallocated at this point, if this buffer was the
1718 // last reference to it.
1719 if (res != OK) {
1720 ALOGE("%s: RequestThread: Can't return input buffer for frame %d to"
1721 " its stream:%s (%d)", __FUNCTION__,
1722 request.frame_number, strerror(-res), res);
1723 // TODO: Report error upstream
1724 }
1725 }
1726
1727
1728
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001729 return true;
1730}
1731
1732void Camera3Device::RequestThread::cleanUpFailedRequest(
1733 camera3_capture_request_t &request,
1734 sp<CaptureRequest> &nextRequest,
1735 Vector<camera3_stream_buffer_t> &outputBuffers) {
1736
1737 if (request.settings != NULL) {
1738 nextRequest->mSettings.unlock(request.settings);
1739 }
1740 if (request.input_buffer != NULL) {
1741 request.input_buffer->status = CAMERA3_BUFFER_STATUS_ERROR;
Igor Murashkin5a269fa2013-04-15 14:59:22 -07001742 nextRequest->mInputStream->returnInputBuffer(*(request.input_buffer));
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001743 }
1744 for (size_t i = 0; i < request.num_output_buffers; i++) {
1745 outputBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
1746 nextRequest->mOutputStreams.editItemAt(i)->returnBuffer(
1747 outputBuffers[i], 0);
1748 }
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001749}
1750
1751sp<Camera3Device::CaptureRequest>
1752 Camera3Device::RequestThread::waitForNextRequest() {
1753 status_t res;
1754 sp<CaptureRequest> nextRequest;
1755
1756 // Optimized a bit for the simple steady-state case (single repeating
1757 // request), to avoid putting that request in the queue temporarily.
1758 Mutex::Autolock l(mRequestLock);
1759
1760 while (mRequestQueue.empty()) {
1761 if (!mRepeatingRequests.empty()) {
1762 // Always atomically enqueue all requests in a repeating request
1763 // list. Guarantees a complete in-sequence set of captures to
1764 // application.
1765 const RequestList &requests = mRepeatingRequests;
1766 RequestList::const_iterator firstRequest =
1767 requests.begin();
1768 nextRequest = *firstRequest;
1769 mRequestQueue.insert(mRequestQueue.end(),
1770 ++firstRequest,
1771 requests.end());
1772 // No need to wait any longer
1773 break;
1774 }
1775
1776 res = mRequestSignal.waitRelative(mRequestLock, kRequestTimeout);
1777
1778 if (res == TIMED_OUT) {
1779 // Signal that we're paused by starvation
1780 Mutex::Autolock pl(mPauseLock);
1781 if (mPaused == false) {
1782 mPaused = true;
1783 mPausedSignal.signal();
1784 }
1785 // Stop waiting for now and let thread management happen
1786 return NULL;
1787 }
1788 }
1789
1790 if (nextRequest == NULL) {
1791 // Don't have a repeating request already in hand, so queue
1792 // must have an entry now.
1793 RequestList::iterator firstRequest =
1794 mRequestQueue.begin();
1795 nextRequest = *firstRequest;
1796 mRequestQueue.erase(firstRequest);
1797 }
1798
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -07001799 // In case we've been unpaused by setPaused clearing mDoPause, need to
1800 // update internal pause state (capture/setRepeatingRequest unpause
1801 // directly).
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001802 Mutex::Autolock pl(mPauseLock);
1803 mPaused = false;
1804
1805 // Check if we've reconfigured since last time, and reset the preview
1806 // request if so. Can't use 'NULL request == repeat' across configure calls.
1807 if (mReconfigured) {
1808 mPrevRequest.clear();
1809 mReconfigured = false;
1810 }
1811
1812 return nextRequest;
1813}
1814
1815bool Camera3Device::RequestThread::waitIfPaused() {
1816 status_t res;
1817 Mutex::Autolock l(mPauseLock);
1818 while (mDoPause) {
1819 // Signal that we're paused by request
1820 if (mPaused == false) {
1821 mPaused = true;
1822 mPausedSignal.signal();
1823 }
1824 res = mDoPauseSignal.waitRelative(mPauseLock, kRequestTimeout);
1825 if (res == TIMED_OUT) {
1826 return true;
1827 }
1828 }
1829 // We don't set mPaused to false here, because waitForNextRequest needs
1830 // to further manage the paused state in case of starvation.
1831 return false;
1832}
1833
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -07001834void Camera3Device::RequestThread::unpauseForNewRequests() {
1835 // With work to do, mark thread as unpaused.
1836 // If paused by request (setPaused), don't resume, to avoid
1837 // extra signaling/waiting overhead to waitUntilPaused
1838 Mutex::Autolock p(mPauseLock);
1839 if (!mDoPause) {
1840 mPaused = false;
1841 }
1842}
1843
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -07001844void Camera3Device::RequestThread::setErrorState(const char *fmt, ...) {
1845 sp<Camera3Device> parent = mParent.promote();
1846 if (parent != NULL) {
1847 va_list args;
1848 va_start(args, fmt);
1849
1850 parent->setErrorStateV(fmt, args);
1851
1852 va_end(args);
1853 }
1854}
1855
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001856status_t Camera3Device::RequestThread::insertTriggers(
1857 const sp<CaptureRequest> &request) {
1858
1859 Mutex::Autolock al(mTriggerMutex);
1860
1861 CameraMetadata &metadata = request->mSettings;
1862 size_t count = mTriggerMap.size();
1863
1864 for (size_t i = 0; i < count; ++i) {
1865 RequestTrigger trigger = mTriggerMap.valueAt(i);
1866
1867 uint32_t tag = trigger.metadataTag;
1868 camera_metadata_entry entry = metadata.find(tag);
1869
1870 if (entry.count > 0) {
1871 /**
1872 * Already has an entry for this trigger in the request.
1873 * Rewrite it with our requested trigger value.
1874 */
1875 RequestTrigger oldTrigger = trigger;
1876
1877 oldTrigger.entryValue = entry.data.u8[0];
1878
1879 mTriggerReplacedMap.add(tag, oldTrigger);
1880 } else {
1881 /**
1882 * More typical, no trigger entry, so we just add it
1883 */
1884 mTriggerRemovedMap.add(tag, trigger);
1885 }
1886
1887 status_t res;
1888
1889 switch (trigger.getTagType()) {
1890 case TYPE_BYTE: {
1891 uint8_t entryValue = static_cast<uint8_t>(trigger.entryValue);
1892 res = metadata.update(tag,
1893 &entryValue,
1894 /*count*/1);
1895 break;
1896 }
1897 case TYPE_INT32:
1898 res = metadata.update(tag,
1899 &trigger.entryValue,
1900 /*count*/1);
1901 break;
1902 default:
1903 ALOGE("%s: Type not supported: 0x%x",
1904 __FUNCTION__,
1905 trigger.getTagType());
1906 return INVALID_OPERATION;
1907 }
1908
1909 if (res != OK) {
1910 ALOGE("%s: Failed to update request metadata with trigger tag %s"
1911 ", value %d", __FUNCTION__, trigger.getTagName(),
1912 trigger.entryValue);
1913 return res;
1914 }
1915
1916 ALOGV("%s: Mixed in trigger %s, value %d", __FUNCTION__,
1917 trigger.getTagName(),
1918 trigger.entryValue);
1919 }
1920
1921 mTriggerMap.clear();
1922
1923 return count;
1924}
1925
1926status_t Camera3Device::RequestThread::removeTriggers(
1927 const sp<CaptureRequest> &request) {
1928 Mutex::Autolock al(mTriggerMutex);
1929
1930 CameraMetadata &metadata = request->mSettings;
1931
1932 /**
1933 * Replace all old entries with their old values.
1934 */
1935 for (size_t i = 0; i < mTriggerReplacedMap.size(); ++i) {
1936 RequestTrigger trigger = mTriggerReplacedMap.valueAt(i);
1937
1938 status_t res;
1939
1940 uint32_t tag = trigger.metadataTag;
1941 switch (trigger.getTagType()) {
1942 case TYPE_BYTE: {
1943 uint8_t entryValue = static_cast<uint8_t>(trigger.entryValue);
1944 res = metadata.update(tag,
1945 &entryValue,
1946 /*count*/1);
1947 break;
1948 }
1949 case TYPE_INT32:
1950 res = metadata.update(tag,
1951 &trigger.entryValue,
1952 /*count*/1);
1953 break;
1954 default:
1955 ALOGE("%s: Type not supported: 0x%x",
1956 __FUNCTION__,
1957 trigger.getTagType());
1958 return INVALID_OPERATION;
1959 }
1960
1961 if (res != OK) {
1962 ALOGE("%s: Failed to restore request metadata with trigger tag %s"
1963 ", trigger value %d", __FUNCTION__,
1964 trigger.getTagName(), trigger.entryValue);
1965 return res;
1966 }
1967 }
1968 mTriggerReplacedMap.clear();
1969
1970 /**
1971 * Remove all new entries.
1972 */
1973 for (size_t i = 0; i < mTriggerRemovedMap.size(); ++i) {
1974 RequestTrigger trigger = mTriggerRemovedMap.valueAt(i);
1975 status_t res = metadata.erase(trigger.metadataTag);
1976
1977 if (res != OK) {
1978 ALOGE("%s: Failed to erase metadata with trigger tag %s"
1979 ", trigger value %d", __FUNCTION__,
1980 trigger.getTagName(), trigger.entryValue);
1981 return res;
1982 }
1983 }
1984 mTriggerRemovedMap.clear();
1985
1986 return OK;
1987}
1988
1989
1990
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001991/**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001992 * Static callback forwarding methods from HAL to instance
1993 */
1994
1995void Camera3Device::sProcessCaptureResult(const camera3_callback_ops *cb,
1996 const camera3_capture_result *result) {
1997 Camera3Device *d =
1998 const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb));
1999 d->processCaptureResult(result);
2000}
2001
2002void Camera3Device::sNotify(const camera3_callback_ops *cb,
2003 const camera3_notify_msg *msg) {
2004 Camera3Device *d =
2005 const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb));
2006 d->notify(msg);
2007}
2008
2009}; // namespace android