blob: 748f3a74af979132d50de5f87d50ad08a453346b [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
28#include <utils/Log.h>
29#include <utils/Trace.h>
30#include <utils/Timers.h>
31#include "Camera3Device.h"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080032#include "camera3/Camera3OutputStream.h"
Igor Murashkin5a269fa2013-04-15 14:59:22 -070033#include "camera3/Camera3InputStream.h"
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080034
35using namespace android::camera3;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080036
37namespace android {
38
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080039Camera3Device::Camera3Device(int id):
40 mId(id),
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080041 mHal3Device(NULL),
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -070042 mStatus(STATUS_UNINITIALIZED),
43 mListener(NULL)
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080044{
45 ATRACE_CALL();
46 camera3_callback_ops::notify = &sNotify;
47 camera3_callback_ops::process_capture_result = &sProcessCaptureResult;
48 ALOGV("%s: Created device for camera %d", __FUNCTION__, id);
49}
50
51Camera3Device::~Camera3Device()
52{
53 ATRACE_CALL();
54 ALOGV("%s: Tearing down for camera id %d", __FUNCTION__, mId);
55 disconnect();
56}
57
Igor Murashkin71381052013-03-04 14:53:08 -080058int Camera3Device::getId() const {
59 return mId;
60}
61
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080062/**
63 * CameraDeviceBase interface
64 */
65
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080066status_t Camera3Device::initialize(camera_module_t *module)
67{
68 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080069 Mutex::Autolock l(mLock);
70
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080071 ALOGV("%s: Initializing device for camera %d", __FUNCTION__, mId);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080072 if (mStatus != STATUS_UNINITIALIZED) {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080073 ALOGE("%s: Already initialized!", __FUNCTION__);
74 return INVALID_OPERATION;
75 }
76
77 /** Open HAL device */
78
79 status_t res;
80 String8 deviceName = String8::format("%d", mId);
81
82 camera3_device_t *device;
83
84 res = module->common.methods->open(&module->common, deviceName.string(),
85 reinterpret_cast<hw_device_t**>(&device));
86
87 if (res != OK) {
88 ALOGE("%s: Could not open camera %d: %s (%d)", __FUNCTION__,
89 mId, strerror(-res), res);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080090 mStatus = STATUS_ERROR;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080091 return res;
92 }
93
94 /** Cross-check device version */
95
96 if (device->common.version != CAMERA_DEVICE_API_VERSION_3_0) {
97 ALOGE("%s: Could not open camera %d: "
98 "Camera device is not version %x, reports %x instead",
99 __FUNCTION__, mId, CAMERA_DEVICE_API_VERSION_3_0,
100 device->common.version);
101 device->common.close(&device->common);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800102 mStatus = STATUS_ERROR;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800103 return BAD_VALUE;
104 }
105
106 camera_info info;
107 res = module->get_camera_info(mId, &info);
108 if (res != OK) return res;
109
110 if (info.device_version != device->common.version) {
111 ALOGE("%s: HAL reporting mismatched camera_info version (%x)"
112 " and device version (%x).", __FUNCTION__,
113 device->common.version, info.device_version);
114 device->common.close(&device->common);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800115 mStatus = STATUS_ERROR;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800116 return BAD_VALUE;
117 }
118
119 /** Initialize device with callback functions */
120
121 res = device->ops->initialize(device, this);
122 if (res != OK) {
123 ALOGE("%s: Camera %d: Unable to initialize HAL device: %s (%d)",
124 __FUNCTION__, mId, strerror(-res), res);
125 device->common.close(&device->common);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800126 mStatus = STATUS_ERROR;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800127 return BAD_VALUE;
128 }
129
130 /** Get vendor metadata tags */
131
132 mVendorTagOps.get_camera_vendor_section_name = NULL;
133
134 device->ops->get_metadata_vendor_tag_ops(device, &mVendorTagOps);
135
136 if (mVendorTagOps.get_camera_vendor_section_name != NULL) {
137 res = set_camera_metadata_vendor_tag_ops(&mVendorTagOps);
138 if (res != OK) {
139 ALOGE("%s: Camera %d: Unable to set tag ops: %s (%d)",
140 __FUNCTION__, mId, strerror(-res), res);
141 device->common.close(&device->common);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800142 mStatus = STATUS_ERROR;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800143 return res;
144 }
145 }
146
147 /** Start up request queue thread */
148
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800149 mRequestThread = new RequestThread(this, device);
150 res = mRequestThread->run(String8::format("C3Dev-%d-ReqQueue", mId).string());
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800151 if (res != OK) {
152 ALOGE("%s: Camera %d: Unable to start request queue thread: %s (%d)",
153 __FUNCTION__, mId, strerror(-res), res);
154 device->common.close(&device->common);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800155 mRequestThread.clear();
156 mStatus = STATUS_ERROR;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800157 return res;
158 }
159
160 /** Everything is good to go */
161
162 mDeviceInfo = info.static_camera_characteristics;
163 mHal3Device = device;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800164 mStatus = STATUS_IDLE;
165 mNextStreamId = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800166
167 return OK;
168}
169
170status_t Camera3Device::disconnect() {
171 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800172 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800173
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800174 ALOGV("%s: E", __FUNCTION__);
175
176 status_t res;
177 if (mStatus == STATUS_UNINITIALIZED) return OK;
178
179 if (mStatus == STATUS_ACTIVE ||
180 (mStatus == STATUS_ERROR && mRequestThread != NULL)) {
181 res = mRequestThread->clearRepeatingRequests();
182 if (res != OK) {
183 ALOGE("%s: Can't stop streaming", __FUNCTION__);
184 return res;
185 }
186 res = waitUntilDrainedLocked();
187 if (res != OK) {
188 ALOGE("%s: Timeout waiting for HAL to drain", __FUNCTION__);
189 return res;
190 }
191 }
192 assert(mStatus == STATUS_IDLE || mStatus == STATUS_ERROR);
193
194 if (mRequestThread != NULL) {
195 mRequestThread->requestExit();
196 }
197
198 mOutputStreams.clear();
199 mInputStream.clear();
200
201 if (mRequestThread != NULL) {
202 mRequestThread->join();
203 mRequestThread.clear();
204 }
205
206 if (mHal3Device != NULL) {
207 mHal3Device->common.close(&mHal3Device->common);
208 mHal3Device = NULL;
209 }
210
211 mStatus = STATUS_UNINITIALIZED;
212
213 ALOGV("%s: X", __FUNCTION__);
214 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800215}
216
217status_t Camera3Device::dump(int fd, const Vector<String16> &args) {
218 ATRACE_CALL();
219 (void)args;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800220 String8 lines;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800221
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800222 const char *status =
223 mStatus == STATUS_ERROR ? "ERROR" :
224 mStatus == STATUS_UNINITIALIZED ? "UNINITIALIZED" :
225 mStatus == STATUS_IDLE ? "IDLE" :
226 mStatus == STATUS_ACTIVE ? "ACTIVE" :
227 "Unknown";
228 lines.appendFormat(" Device status: %s\n", status);
229 lines.appendFormat(" Stream configuration:\n");
230
231 if (mInputStream != NULL) {
232 write(fd, lines.string(), lines.size());
233 mInputStream->dump(fd, args);
234 } else {
235 lines.appendFormat(" No input stream.\n");
236 write(fd, lines.string(), lines.size());
237 }
238 for (size_t i = 0; i < mOutputStreams.size(); i++) {
239 mOutputStreams[i]->dump(fd,args);
240 }
241
242 if (mHal3Device != NULL) {
243 lines = String8(" HAL device dump:\n");
244 write(fd, lines.string(), lines.size());
245 mHal3Device->ops->dump(mHal3Device, fd);
246 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800247
248 return OK;
249}
250
251const CameraMetadata& Camera3Device::info() const {
252 ALOGVV("%s: E", __FUNCTION__);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800253 if (CC_UNLIKELY(mStatus == STATUS_UNINITIALIZED ||
254 mStatus == STATUS_ERROR)) {
255 ALOGE("%s: Access to static info %s!", __FUNCTION__,
256 mStatus == STATUS_ERROR ?
257 "when in error state" : "before init");
258 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800259 return mDeviceInfo;
260}
261
262status_t Camera3Device::capture(CameraMetadata &request) {
263 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800264 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800265
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700266 // TODO: take ownership of the request
267
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800268 switch (mStatus) {
269 case STATUS_ERROR:
270 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
271 return INVALID_OPERATION;
272 case STATUS_UNINITIALIZED:
273 ALOGE("%s: Device not initialized", __FUNCTION__);
274 return INVALID_OPERATION;
275 case STATUS_IDLE:
276 case STATUS_ACTIVE:
277 // OK
278 break;
279 default:
280 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
281 return INVALID_OPERATION;
282 }
283
284 sp<CaptureRequest> newRequest = setUpRequestLocked(request);
285 if (newRequest == NULL) {
286 ALOGE("%s: Can't create capture request", __FUNCTION__);
287 return BAD_VALUE;
288 }
289
290 return mRequestThread->queueRequest(newRequest);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800291}
292
293
294status_t Camera3Device::setStreamingRequest(const CameraMetadata &request) {
295 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800296 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800297
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800298 switch (mStatus) {
299 case STATUS_ERROR:
300 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
301 return INVALID_OPERATION;
302 case STATUS_UNINITIALIZED:
303 ALOGE("%s: Device not initialized", __FUNCTION__);
304 return INVALID_OPERATION;
305 case STATUS_IDLE:
306 case STATUS_ACTIVE:
307 // OK
308 break;
309 default:
310 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
311 return INVALID_OPERATION;
312 }
313
314 sp<CaptureRequest> newRepeatingRequest = setUpRequestLocked(request);
315 if (newRepeatingRequest == NULL) {
316 ALOGE("%s: Can't create repeating request", __FUNCTION__);
317 return BAD_VALUE;
318 }
319
320 RequestList newRepeatingRequests;
321 newRepeatingRequests.push_back(newRepeatingRequest);
322
323 return mRequestThread->setRepeatingRequests(newRepeatingRequests);
324}
325
326
327sp<Camera3Device::CaptureRequest> Camera3Device::setUpRequestLocked(
328 const CameraMetadata &request) {
329 status_t res;
330
331 if (mStatus == STATUS_IDLE) {
332 res = configureStreamsLocked();
333 if (res != OK) {
334 ALOGE("%s: Can't set up streams: %s (%d)",
335 __FUNCTION__, strerror(-res), res);
336 return NULL;
337 }
338 }
339
340 sp<CaptureRequest> newRequest = createCaptureRequest(request);
341 return newRequest;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800342}
343
344status_t Camera3Device::clearStreamingRequest() {
345 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800346 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800347
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800348 switch (mStatus) {
349 case STATUS_ERROR:
350 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
351 return INVALID_OPERATION;
352 case STATUS_UNINITIALIZED:
353 ALOGE("%s: Device not initialized", __FUNCTION__);
354 return INVALID_OPERATION;
355 case STATUS_IDLE:
356 case STATUS_ACTIVE:
357 // OK
358 break;
359 default:
360 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
361 return INVALID_OPERATION;
362 }
363
364 return mRequestThread->clearRepeatingRequests();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800365}
366
367status_t Camera3Device::waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) {
368 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800369
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700370 return mRequestThread->waitUntilRequestProcessed(requestId, timeout);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800371}
372
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700373status_t Camera3Device::createInputStream(
374 uint32_t width, uint32_t height, int format, int *id) {
375 ATRACE_CALL();
376 Mutex::Autolock l(mLock);
377
378 status_t res;
379 bool wasActive = false;
380
381 switch (mStatus) {
382 case STATUS_ERROR:
383 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
384 return INVALID_OPERATION;
385 case STATUS_UNINITIALIZED:
386 ALOGE("%s: Device not initialized", __FUNCTION__);
387 return INVALID_OPERATION;
388 case STATUS_IDLE:
389 // OK
390 break;
391 case STATUS_ACTIVE:
392 ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__);
393 mRequestThread->setPaused(true);
394 res = waitUntilDrainedLocked();
395 if (res != OK) {
396 ALOGE("%s: Can't pause captures to reconfigure streams!",
397 __FUNCTION__);
398 mStatus = STATUS_ERROR;
399 return res;
400 }
401 wasActive = true;
402 break;
403 default:
404 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
405 return INVALID_OPERATION;
406 }
407 assert(mStatus == STATUS_IDLE);
408
409 if (mInputStream != 0) {
410 ALOGE("%s: Cannot create more than 1 input stream", __FUNCTION__);
411 return INVALID_OPERATION;
412 }
413
414 sp<Camera3InputStream> newStream = new Camera3InputStream(mNextStreamId,
415 width, height, format);
416
417 mInputStream = newStream;
418
419 *id = mNextStreamId++;
420
421 // Continue captures if active at start
422 if (wasActive) {
423 ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__);
424 res = configureStreamsLocked();
425 if (res != OK) {
426 ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)",
427 __FUNCTION__, mNextStreamId, strerror(-res), res);
428 return res;
429 }
430 mRequestThread->setPaused(false);
431 }
432
433 return OK;
434}
435
Igor Murashkin2fba5842013-04-22 14:03:54 -0700436
437status_t Camera3Device::createZslStream(
438 uint32_t width, uint32_t height,
439 int depth,
440 /*out*/
441 int *id,
442 sp<Camera3ZslStream>* zslStream) {
443 ATRACE_CALL();
444 Mutex::Autolock l(mLock);
445
446 status_t res;
447 bool wasActive = false;
448
449 switch (mStatus) {
450 case STATUS_ERROR:
451 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
452 return INVALID_OPERATION;
453 case STATUS_UNINITIALIZED:
454 ALOGE("%s: Device not initialized", __FUNCTION__);
455 return INVALID_OPERATION;
456 case STATUS_IDLE:
457 // OK
458 break;
459 case STATUS_ACTIVE:
460 ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__);
461 mRequestThread->setPaused(true);
462 res = waitUntilDrainedLocked();
463 if (res != OK) {
464 ALOGE("%s: Can't pause captures to reconfigure streams!",
465 __FUNCTION__);
466 mStatus = STATUS_ERROR;
467 return res;
468 }
469 wasActive = true;
470 break;
471 default:
472 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
473 return INVALID_OPERATION;
474 }
475 assert(mStatus == STATUS_IDLE);
476
477 if (mInputStream != 0) {
478 ALOGE("%s: Cannot create more than 1 input stream", __FUNCTION__);
479 return INVALID_OPERATION;
480 }
481
482 sp<Camera3ZslStream> newStream = new Camera3ZslStream(mNextStreamId,
483 width, height, depth);
484
485 res = mOutputStreams.add(mNextStreamId, newStream);
486 if (res < 0) {
487 ALOGE("%s: Can't add new stream to set: %s (%d)",
488 __FUNCTION__, strerror(-res), res);
489 return res;
490 }
491 mInputStream = newStream;
492
493 *id = mNextStreamId++;
494 *zslStream = newStream;
495
496 // Continue captures if active at start
497 if (wasActive) {
498 ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__);
499 res = configureStreamsLocked();
500 if (res != OK) {
501 ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)",
502 __FUNCTION__, mNextStreamId, strerror(-res), res);
503 return res;
504 }
505 mRequestThread->setPaused(false);
506 }
507
508 return OK;
509}
510
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800511status_t Camera3Device::createStream(sp<ANativeWindow> consumer,
512 uint32_t width, uint32_t height, int format, size_t size, int *id) {
513 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800514 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800515
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800516 status_t res;
517 bool wasActive = false;
518
519 switch (mStatus) {
520 case STATUS_ERROR:
521 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
522 return INVALID_OPERATION;
523 case STATUS_UNINITIALIZED:
524 ALOGE("%s: Device not initialized", __FUNCTION__);
525 return INVALID_OPERATION;
526 case STATUS_IDLE:
527 // OK
528 break;
529 case STATUS_ACTIVE:
530 ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__);
531 mRequestThread->setPaused(true);
532 res = waitUntilDrainedLocked();
533 if (res != OK) {
534 ALOGE("%s: Can't pause captures to reconfigure streams!",
535 __FUNCTION__);
536 mStatus = STATUS_ERROR;
537 return res;
538 }
539 wasActive = true;
540 break;
541 default:
542 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
543 return INVALID_OPERATION;
544 }
545 assert(mStatus == STATUS_IDLE);
546
547 sp<Camera3OutputStream> newStream;
548 if (format == HAL_PIXEL_FORMAT_BLOB) {
549 newStream = new Camera3OutputStream(mNextStreamId, consumer,
550 width, height, size, format);
551 } else {
552 newStream = new Camera3OutputStream(mNextStreamId, consumer,
553 width, height, format);
554 }
555
556 res = mOutputStreams.add(mNextStreamId, newStream);
557 if (res < 0) {
558 ALOGE("%s: Can't add new stream to set: %s (%d)",
559 __FUNCTION__, strerror(-res), res);
560 return res;
561 }
562
563 *id = mNextStreamId++;
564
565 // Continue captures if active at start
566 if (wasActive) {
567 ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__);
568 res = configureStreamsLocked();
569 if (res != OK) {
570 ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)",
571 __FUNCTION__, mNextStreamId, strerror(-res), res);
572 return res;
573 }
574 mRequestThread->setPaused(false);
575 }
576
577 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800578}
579
580status_t Camera3Device::createReprocessStreamFromStream(int outputId, int *id) {
581 ATRACE_CALL();
582 (void)outputId; (void)id;
583
584 ALOGE("%s: Unimplemented", __FUNCTION__);
585 return INVALID_OPERATION;
586}
587
588
589status_t Camera3Device::getStreamInfo(int id,
590 uint32_t *width, uint32_t *height, uint32_t *format) {
591 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800592 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800593
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800594 switch (mStatus) {
595 case STATUS_ERROR:
596 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
597 return INVALID_OPERATION;
598 case STATUS_UNINITIALIZED:
599 ALOGE("%s: Device not initialized!", __FUNCTION__);
600 return INVALID_OPERATION;
601 case STATUS_IDLE:
602 case STATUS_ACTIVE:
603 // OK
604 break;
605 default:
606 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
607 return INVALID_OPERATION;
608 }
609
610 ssize_t idx = mOutputStreams.indexOfKey(id);
611 if (idx == NAME_NOT_FOUND) {
612 ALOGE("%s: Stream %d is unknown", __FUNCTION__, id);
613 return idx;
614 }
615
616 if (width) *width = mOutputStreams[idx]->getWidth();
617 if (height) *height = mOutputStreams[idx]->getHeight();
618 if (format) *format = mOutputStreams[idx]->getFormat();
619
620 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800621}
622
623status_t Camera3Device::setStreamTransform(int id,
624 int transform) {
625 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800626 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800627
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800628 switch (mStatus) {
629 case STATUS_ERROR:
630 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
631 return INVALID_OPERATION;
632 case STATUS_UNINITIALIZED:
633 ALOGE("%s: Device not initialized", __FUNCTION__);
634 return INVALID_OPERATION;
635 case STATUS_IDLE:
636 case STATUS_ACTIVE:
637 // OK
638 break;
639 default:
640 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
641 return INVALID_OPERATION;
642 }
643
644 ssize_t idx = mOutputStreams.indexOfKey(id);
645 if (idx == NAME_NOT_FOUND) {
646 ALOGE("%s: Stream %d does not exist",
647 __FUNCTION__, id);
648 return BAD_VALUE;
649 }
650
651 return mOutputStreams.editValueAt(idx)->setTransform(transform);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800652}
653
654status_t Camera3Device::deleteStream(int id) {
655 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800656 Mutex::Autolock l(mLock);
657 status_t res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800658
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800659 // CameraDevice semantics require device to already be idle before
660 // deleteStream is called, unlike for createStream.
661 if (mStatus != STATUS_IDLE) {
662 ALOGE("%s: Device not idle", __FUNCTION__);
663 return INVALID_OPERATION;
664 }
665
Igor Murashkin2fba5842013-04-22 14:03:54 -0700666 sp<Camera3StreamInterface> deletedStream;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800667 if (mInputStream != NULL && id == mInputStream->getId()) {
668 deletedStream = mInputStream;
669 mInputStream.clear();
670 } else {
671 ssize_t idx = mOutputStreams.indexOfKey(id);
672 if (idx == NAME_NOT_FOUND) {
673 ALOGE("%s: Stream %d does not exist",
674 __FUNCTION__, id);
675 return BAD_VALUE;
676 }
677 deletedStream = mOutputStreams.editValueAt(idx);
678 mOutputStreams.removeItem(id);
679 }
680
681 // Free up the stream endpoint so that it can be used by some other stream
682 res = deletedStream->disconnect();
683 if (res != OK) {
684 ALOGE("%s: Can't disconnect deleted stream", __FUNCTION__);
685 // fall through since we want to still list the stream as deleted.
686 }
687 mDeletedStreams.add(deletedStream);
688
689 return res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800690}
691
692status_t Camera3Device::deleteReprocessStream(int id) {
693 ATRACE_CALL();
694 (void)id;
695
696 ALOGE("%s: Unimplemented", __FUNCTION__);
697 return INVALID_OPERATION;
698}
699
700
701status_t Camera3Device::createDefaultRequest(int templateId,
702 CameraMetadata *request) {
703 ATRACE_CALL();
704 ALOGV("%s: E", __FUNCTION__);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800705 Mutex::Autolock l(mLock);
706
707 switch (mStatus) {
708 case STATUS_ERROR:
709 ALOGE("%s: Device has encountered a serious error", __FUNCTION__);
710 return INVALID_OPERATION;
711 case STATUS_UNINITIALIZED:
712 ALOGE("%s: Device is not initialized!", __FUNCTION__);
713 return INVALID_OPERATION;
714 case STATUS_IDLE:
715 case STATUS_ACTIVE:
716 // OK
717 break;
718 default:
719 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
720 return INVALID_OPERATION;
721 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800722
723 const camera_metadata_t *rawRequest;
724 rawRequest = mHal3Device->ops->construct_default_request_settings(
725 mHal3Device, templateId);
726 if (rawRequest == NULL) return DEAD_OBJECT;
727 *request = rawRequest;
728
729 return OK;
730}
731
732status_t Camera3Device::waitUntilDrained() {
733 ATRACE_CALL();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800734 Mutex::Autolock l(mLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800735
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800736 return waitUntilDrainedLocked();
737}
738
739status_t Camera3Device::waitUntilDrainedLocked() {
740 ATRACE_CALL();
741 status_t res;
742
743 switch (mStatus) {
744 case STATUS_UNINITIALIZED:
745 case STATUS_IDLE:
746 ALOGV("%s: Already idle", __FUNCTION__);
747 return OK;
748 case STATUS_ERROR:
749 case STATUS_ACTIVE:
750 // Need to shut down
751 break;
752 default:
753 ALOGE("%s: Unexpected status: %d", __FUNCTION__, mStatus);
754 return INVALID_OPERATION;
755 }
756
757 if (mRequestThread != NULL) {
758 res = mRequestThread->waitUntilPaused(kShutdownTimeout);
759 if (res != OK) {
760 ALOGE("%s: Can't stop request thread in %f seconds!",
761 __FUNCTION__, kShutdownTimeout/1e9);
762 mStatus = STATUS_ERROR;
763 return res;
764 }
765 }
766 if (mInputStream != NULL) {
767 res = mInputStream->waitUntilIdle(kShutdownTimeout);
768 if (res != OK) {
769 ALOGE("%s: Can't idle input stream %d in %f seconds!",
770 __FUNCTION__, mInputStream->getId(), kShutdownTimeout/1e9);
771 mStatus = STATUS_ERROR;
772 return res;
773 }
774 }
775 for (size_t i = 0; i < mOutputStreams.size(); i++) {
776 res = mOutputStreams.editValueAt(i)->waitUntilIdle(kShutdownTimeout);
777 if (res != OK) {
778 ALOGE("%s: Can't idle output stream %d in %f seconds!",
779 __FUNCTION__, mOutputStreams.keyAt(i),
780 kShutdownTimeout/1e9);
781 mStatus = STATUS_ERROR;
782 return res;
783 }
784 }
785
786 if (mStatus != STATUS_ERROR) {
787 mStatus = STATUS_IDLE;
788 }
789
790 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800791}
792
793status_t Camera3Device::setNotifyCallback(NotificationListener *listener) {
794 ATRACE_CALL();
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700795 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800796
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700797 if (listener != NULL && mListener != NULL) {
798 ALOGW("%s: Replacing old callback listener", __FUNCTION__);
799 }
800 mListener = listener;
801
802 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800803}
804
805status_t Camera3Device::waitForNextFrame(nsecs_t timeout) {
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700806 ATRACE_CALL();
807 status_t res;
808 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800809
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700810 while (mResultQueue.empty()) {
811 res = mResultSignal.waitRelative(mOutputLock, timeout);
812 if (res == TIMED_OUT) {
813 return res;
814 } else if (res != OK) {
815 ALOGE("%s: Camera %d: Error waiting for frame: %s (%d)",
816 __FUNCTION__, mId, strerror(-res), res);
817 return res;
818 }
819 }
820 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800821}
822
823status_t Camera3Device::getNextFrame(CameraMetadata *frame) {
824 ATRACE_CALL();
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700825 Mutex::Autolock l(mOutputLock);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800826
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700827 if (mResultQueue.empty()) {
828 return NOT_ENOUGH_DATA;
829 }
830
831 CameraMetadata &result = *(mResultQueue.begin());
832 frame->acquire(result);
833 mResultQueue.erase(mResultQueue.begin());
834
835 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800836}
837
838status_t Camera3Device::triggerAutofocus(uint32_t id) {
839 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800840
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700841 ALOGV("%s: Triggering autofocus, id %d", __FUNCTION__, id);
842 // Mix-in this trigger into the next request and only the next request.
843 RequestTrigger trigger[] = {
844 {
845 ANDROID_CONTROL_AF_TRIGGER,
846 ANDROID_CONTROL_AF_TRIGGER_START
847 },
848 {
849 ANDROID_CONTROL_AF_TRIGGER_ID,
850 static_cast<int32_t>(id)
851 },
852 };
853
854 return mRequestThread->queueTrigger(trigger,
855 sizeof(trigger)/sizeof(trigger[0]));
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800856}
857
858status_t Camera3Device::triggerCancelAutofocus(uint32_t id) {
859 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800860
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700861 ALOGV("%s: Triggering cancel autofocus, id %d", __FUNCTION__, id);
862 // Mix-in this trigger into the next request and only the next request.
863 RequestTrigger trigger[] = {
864 {
865 ANDROID_CONTROL_AF_TRIGGER,
866 ANDROID_CONTROL_AF_TRIGGER_CANCEL
867 },
868 {
869 ANDROID_CONTROL_AF_TRIGGER_ID,
870 static_cast<int32_t>(id)
871 },
872 };
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800873
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700874 return mRequestThread->queueTrigger(trigger,
875 sizeof(trigger)/sizeof(trigger[0]));
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800876}
877
878status_t Camera3Device::triggerPrecaptureMetering(uint32_t id) {
879 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800880
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700881 ALOGV("%s: Triggering precapture metering, id %d", __FUNCTION__, id);
882 // Mix-in this trigger into the next request and only the next request.
883 RequestTrigger trigger[] = {
884 {
885 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER,
886 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_START
887 },
888 {
889 ANDROID_CONTROL_AE_PRECAPTURE_ID,
890 static_cast<int32_t>(id)
891 },
892 };
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800893
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700894 return mRequestThread->queueTrigger(trigger,
895 sizeof(trigger)/sizeof(trigger[0]));
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800896}
897
898status_t Camera3Device::pushReprocessBuffer(int reprocessStreamId,
899 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) {
900 ATRACE_CALL();
901 (void)reprocessStreamId; (void)buffer; (void)listener;
902
903 ALOGE("%s: Unimplemented", __FUNCTION__);
904 return INVALID_OPERATION;
905}
906
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800907/**
908 * Camera3Device private methods
909 */
910
911sp<Camera3Device::CaptureRequest> Camera3Device::createCaptureRequest(
912 const CameraMetadata &request) {
913 ATRACE_CALL();
914 status_t res;
915
916 sp<CaptureRequest> newRequest = new CaptureRequest;
917 newRequest->mSettings = request;
918
919 camera_metadata_entry_t inputStreams =
920 newRequest->mSettings.find(ANDROID_REQUEST_INPUT_STREAMS);
921 if (inputStreams.count > 0) {
922 if (mInputStream == NULL ||
923 mInputStream->getId() != inputStreams.data.u8[0]) {
924 ALOGE("%s: Request references unknown input stream %d",
925 __FUNCTION__, inputStreams.data.u8[0]);
926 return NULL;
927 }
928 // Lazy completion of stream configuration (allocation/registration)
929 // on first use
930 if (mInputStream->isConfiguring()) {
931 res = mInputStream->finishConfiguration(mHal3Device);
932 if (res != OK) {
933 ALOGE("%s: Unable to finish configuring input stream %d:"
934 " %s (%d)",
935 __FUNCTION__, mInputStream->getId(),
936 strerror(-res), res);
937 return NULL;
938 }
939 }
940
941 newRequest->mInputStream = mInputStream;
942 newRequest->mSettings.erase(ANDROID_REQUEST_INPUT_STREAMS);
943 }
944
945 camera_metadata_entry_t streams =
946 newRequest->mSettings.find(ANDROID_REQUEST_OUTPUT_STREAMS);
947 if (streams.count == 0) {
948 ALOGE("%s: Zero output streams specified!", __FUNCTION__);
949 return NULL;
950 }
951
952 for (size_t i = 0; i < streams.count; i++) {
953 int idx = mOutputStreams.indexOfKey(streams.data.u8[i]);
954 if (idx == NAME_NOT_FOUND) {
955 ALOGE("%s: Request references unknown stream %d",
956 __FUNCTION__, streams.data.u8[i]);
957 return NULL;
958 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700959 sp<Camera3OutputStreamInterface> stream =
960 mOutputStreams.editValueAt(idx);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800961
962 // Lazy completion of stream configuration (allocation/registration)
963 // on first use
964 if (stream->isConfiguring()) {
965 res = stream->finishConfiguration(mHal3Device);
966 if (res != OK) {
967 ALOGE("%s: Unable to finish configuring stream %d: %s (%d)",
968 __FUNCTION__, stream->getId(), strerror(-res), res);
969 return NULL;
970 }
971 }
972
973 newRequest->mOutputStreams.push(stream);
974 }
975 newRequest->mSettings.erase(ANDROID_REQUEST_OUTPUT_STREAMS);
976
977 return newRequest;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800978}
979
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800980status_t Camera3Device::configureStreamsLocked() {
981 ATRACE_CALL();
982 status_t res;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800983
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800984 if (mStatus != STATUS_IDLE) {
985 ALOGE("%s: Not idle", __FUNCTION__);
986 return INVALID_OPERATION;
987 }
988
989 // Start configuring the streams
990
991 camera3_stream_configuration config;
992
993 config.num_streams = (mInputStream != NULL) + mOutputStreams.size();
994
995 Vector<camera3_stream_t*> streams;
996 streams.setCapacity(config.num_streams);
997
998 if (mInputStream != NULL) {
999 camera3_stream_t *inputStream;
1000 inputStream = mInputStream->startConfiguration();
1001 if (inputStream == NULL) {
1002 ALOGE("%s: Can't start input stream configuration",
1003 __FUNCTION__);
1004 // TODO: Make sure the error flow here is correct
1005 return INVALID_OPERATION;
1006 }
1007 streams.add(inputStream);
1008 }
1009
1010 for (size_t i = 0; i < mOutputStreams.size(); i++) {
Igor Murashkin2fba5842013-04-22 14:03:54 -07001011
1012 // Don't configure bidi streams twice, nor add them twice to the list
1013 if (mOutputStreams[i].get() ==
1014 static_cast<Camera3StreamInterface*>(mInputStream.get())) {
1015
1016 config.num_streams--;
1017 continue;
1018 }
1019
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001020 camera3_stream_t *outputStream;
1021 outputStream = mOutputStreams.editValueAt(i)->startConfiguration();
1022 if (outputStream == NULL) {
1023 ALOGE("%s: Can't start output stream configuration",
1024 __FUNCTION__);
1025 // TODO: Make sure the error flow here is correct
1026 return INVALID_OPERATION;
1027 }
1028 streams.add(outputStream);
1029 }
1030
1031 config.streams = streams.editArray();
1032
1033 // Do the HAL configuration; will potentially touch stream
1034 // max_buffers, usage, priv fields.
1035
1036 res = mHal3Device->ops->configure_streams(mHal3Device, &config);
1037
1038 if (res != OK) {
1039 ALOGE("%s: Unable to configure streams with HAL: %s (%d)",
1040 __FUNCTION__, strerror(-res), res);
1041 return res;
1042 }
1043
1044 // Request thread needs to know to avoid using repeat-last-settings protocol
1045 // across configure_streams() calls
1046 mRequestThread->configurationComplete();
1047
1048 // Finish configuring the streams lazily on first reference
1049
1050 mStatus = STATUS_ACTIVE;
1051
1052 return OK;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001053}
1054
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001055
1056/**
1057 * Camera HAL device callback methods
1058 */
1059
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001060void Camera3Device::processCaptureResult(const camera3_capture_result *result) {
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001061 ATRACE_CALL();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001062
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001063 status_t res;
1064
1065 if (result->result == NULL) {
1066 // TODO: Report error upstream
1067 ALOGW("%s: No metadata for frame %d", __FUNCTION__,
1068 result->frame_number);
1069 return;
1070 }
1071
1072 nsecs_t timestamp = 0;
1073 AlgState cur3aState;
1074 AlgState new3aState;
1075 int32_t aeTriggerId = 0;
1076 int32_t afTriggerId = 0;
1077
1078 NotificationListener *listener;
1079
1080 {
1081 Mutex::Autolock l(mOutputLock);
1082
1083 // Push result metadata into queue
1084 mResultQueue.push_back(CameraMetadata());
Igor Murashkind2c90692013-04-02 12:32:32 -07001085 // Lets avoid copies! Too bad there's not a #back method
1086 CameraMetadata &captureResult = *(--mResultQueue.end());
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001087
1088 captureResult = result->result;
Igor Murashkind2c90692013-04-02 12:32:32 -07001089 if (captureResult.update(ANDROID_REQUEST_FRAME_COUNT,
1090 (int32_t*)&result->frame_number, 1) != OK) {
1091 ALOGE("%s: Camera %d: Failed to set frame# in metadata (%d)",
1092 __FUNCTION__, mId, result->frame_number);
1093 // TODO: Report error upstream
1094 } else {
1095 ALOGVV("%s: Camera %d: Set frame# in metadata (%d)",
1096 __FUNCTION__, mId, result->frame_number);
1097 }
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001098
1099 // Get timestamp from result metadata
1100
1101 camera_metadata_entry entry =
1102 captureResult.find(ANDROID_SENSOR_TIMESTAMP);
1103 if (entry.count == 0) {
1104 ALOGE("%s: Camera %d: No timestamp provided by HAL for frame %d!",
1105 __FUNCTION__, mId, result->frame_number);
1106 // TODO: Report error upstream
1107 } else {
1108 timestamp = entry.data.i64[0];
1109 }
1110
1111 // Get 3A states from result metadata
1112
1113 entry = captureResult.find(ANDROID_CONTROL_AE_STATE);
1114 if (entry.count == 0) {
1115 ALOGE("%s: Camera %d: No AE state provided by HAL for frame %d!",
1116 __FUNCTION__, mId, result->frame_number);
1117 } else {
1118 new3aState.aeState =
1119 static_cast<camera_metadata_enum_android_control_ae_state>(
1120 entry.data.u8[0]);
1121 }
1122
1123 entry = captureResult.find(ANDROID_CONTROL_AF_STATE);
1124 if (entry.count == 0) {
1125 ALOGE("%s: Camera %d: No AF state provided by HAL for frame %d!",
1126 __FUNCTION__, mId, result->frame_number);
1127 } else {
1128 new3aState.afState =
1129 static_cast<camera_metadata_enum_android_control_af_state>(
1130 entry.data.u8[0]);
1131 }
1132
1133 entry = captureResult.find(ANDROID_CONTROL_AWB_STATE);
1134 if (entry.count == 0) {
1135 ALOGE("%s: Camera %d: No AWB state provided by HAL for frame %d!",
1136 __FUNCTION__, mId, result->frame_number);
1137 } else {
1138 new3aState.awbState =
1139 static_cast<camera_metadata_enum_android_control_awb_state>(
1140 entry.data.u8[0]);
1141 }
1142
1143 entry = captureResult.find(ANDROID_CONTROL_AF_TRIGGER_ID);
1144 if (entry.count == 0) {
1145 ALOGE("%s: Camera %d: No AF trigger ID provided by HAL for frame %d!",
1146 __FUNCTION__, mId, result->frame_number);
1147 } else {
1148 afTriggerId = entry.data.i32[0];
1149 }
1150
1151 entry = captureResult.find(ANDROID_CONTROL_AE_PRECAPTURE_ID);
1152 if (entry.count == 0) {
1153 ALOGE("%s: Camera %d: No AE precapture trigger ID provided by HAL"
1154 " for frame %d!", __FUNCTION__, mId, result->frame_number);
1155 } else {
1156 aeTriggerId = entry.data.i32[0];
1157 }
1158
1159 listener = mListener;
1160 cur3aState = m3AState;
1161
1162 m3AState = new3aState;
1163 } // scope for mOutputLock
1164
1165 // Return completed buffers to their streams
1166 for (size_t i = 0; i < result->num_output_buffers; i++) {
1167 Camera3Stream *stream =
1168 Camera3Stream::cast(result->output_buffers[i].stream);
1169 res = stream->returnBuffer(result->output_buffers[i], timestamp);
1170 // Note: stream may be deallocated at this point, if this buffer was the
1171 // last reference to it.
1172 if (res != OK) {
1173 ALOGE("%s: Camera %d: Can't return buffer %d for frame %d to its"
1174 " stream:%s (%d)", __FUNCTION__, mId, i,
1175 result->frame_number, strerror(-res), res);
1176 // TODO: Report error upstream
1177 }
1178 }
1179
1180 // Dispatch any 3A change events to listeners
1181 if (listener != NULL) {
1182 if (new3aState.aeState != cur3aState.aeState) {
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001183 ALOGVV("%s: AE state changed from 0x%x to 0x%x",
1184 __FUNCTION__, cur3aState.aeState, new3aState.aeState);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001185 listener->notifyAutoExposure(new3aState.aeState, aeTriggerId);
1186 }
1187 if (new3aState.afState != cur3aState.afState) {
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001188 ALOGVV("%s: AF state changed from 0x%x to 0x%x",
1189 __FUNCTION__, cur3aState.afState, new3aState.afState);
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001190 listener->notifyAutoFocus(new3aState.afState, afTriggerId);
1191 }
1192 if (new3aState.awbState != cur3aState.awbState) {
1193 listener->notifyAutoWhitebalance(new3aState.awbState, aeTriggerId);
1194 }
1195 }
1196
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001197}
1198
1199void Camera3Device::notify(const camera3_notify_msg *msg) {
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001200 NotificationListener *listener;
1201 {
1202 Mutex::Autolock l(mOutputLock);
1203 if (mListener == NULL) return;
1204 listener = mListener;
1205 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001206
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001207 if (msg == NULL) {
1208 ALOGE("%s: Camera %d: HAL sent NULL notify message!",
1209 __FUNCTION__, mId);
1210 return;
1211 }
1212
1213 switch (msg->type) {
1214 case CAMERA3_MSG_ERROR: {
1215 int streamId = 0;
1216 if (msg->message.error.error_stream != NULL) {
1217 Camera3Stream *stream =
1218 Camera3Stream::cast(
1219 msg->message.error.error_stream);
1220 streamId = stream->getId();
1221 }
1222 listener->notifyError(msg->message.error.error_code,
1223 msg->message.error.frame_number, streamId);
1224 break;
1225 }
1226 case CAMERA3_MSG_SHUTTER: {
1227 listener->notifyShutter(msg->message.shutter.frame_number,
1228 msg->message.shutter.timestamp);
1229 break;
1230 }
1231 default:
1232 ALOGE("%s: Camera %d: Unknown notify message from HAL: %d",
1233 __FUNCTION__, mId, msg->type);
1234 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001235}
1236
1237/**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001238 * RequestThread inner class methods
1239 */
1240
1241Camera3Device::RequestThread::RequestThread(wp<Camera3Device> parent,
1242 camera3_device_t *hal3Device) :
1243 Thread(false),
1244 mParent(parent),
1245 mHal3Device(hal3Device),
1246 mReconfigured(false),
1247 mDoPause(false),
1248 mPaused(true),
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001249 mFrameNumber(0),
1250 mLatestRequestId(NAME_NOT_FOUND) {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001251}
1252
1253void Camera3Device::RequestThread::configurationComplete() {
1254 Mutex::Autolock l(mRequestLock);
1255 mReconfigured = true;
1256}
1257
1258status_t Camera3Device::RequestThread::queueRequest(
1259 sp<CaptureRequest> request) {
1260 Mutex::Autolock l(mRequestLock);
1261 mRequestQueue.push_back(request);
1262
1263 return OK;
1264}
1265
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001266
1267status_t Camera3Device::RequestThread::queueTrigger(
1268 RequestTrigger trigger[],
1269 size_t count) {
1270
1271 Mutex::Autolock l(mTriggerMutex);
1272 status_t ret;
1273
1274 for (size_t i = 0; i < count; ++i) {
1275 ret = queueTriggerLocked(trigger[i]);
1276
1277 if (ret != OK) {
1278 return ret;
1279 }
1280 }
1281
1282 return OK;
1283}
1284
1285status_t Camera3Device::RequestThread::queueTriggerLocked(
1286 RequestTrigger trigger) {
1287
1288 uint32_t tag = trigger.metadataTag;
1289 ssize_t index = mTriggerMap.indexOfKey(tag);
1290
1291 switch (trigger.getTagType()) {
1292 case TYPE_BYTE:
1293 // fall-through
1294 case TYPE_INT32:
1295 break;
1296 default:
1297 ALOGE("%s: Type not supported: 0x%x",
1298 __FUNCTION__,
1299 trigger.getTagType());
1300 return INVALID_OPERATION;
1301 }
1302
1303 /**
1304 * Collect only the latest trigger, since we only have 1 field
1305 * in the request settings per trigger tag, and can't send more than 1
1306 * trigger per request.
1307 */
1308 if (index != NAME_NOT_FOUND) {
1309 mTriggerMap.editValueAt(index) = trigger;
1310 } else {
1311 mTriggerMap.add(tag, trigger);
1312 }
1313
1314 return OK;
1315}
1316
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001317status_t Camera3Device::RequestThread::setRepeatingRequests(
1318 const RequestList &requests) {
1319 Mutex::Autolock l(mRequestLock);
1320 mRepeatingRequests.clear();
1321 mRepeatingRequests.insert(mRepeatingRequests.begin(),
1322 requests.begin(), requests.end());
1323 return OK;
1324}
1325
1326status_t Camera3Device::RequestThread::clearRepeatingRequests() {
1327 Mutex::Autolock l(mRequestLock);
1328 mRepeatingRequests.clear();
1329 return OK;
1330}
1331
1332void Camera3Device::RequestThread::setPaused(bool paused) {
1333 Mutex::Autolock l(mPauseLock);
1334 mDoPause = paused;
1335 mDoPauseSignal.signal();
1336}
1337
1338status_t Camera3Device::RequestThread::waitUntilPaused(nsecs_t timeout) {
1339 status_t res;
1340 Mutex::Autolock l(mPauseLock);
1341 while (!mPaused) {
1342 res = mPausedSignal.waitRelative(mPauseLock, timeout);
1343 if (res == TIMED_OUT) {
1344 return res;
1345 }
1346 }
1347 return OK;
1348}
1349
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001350status_t Camera3Device::RequestThread::waitUntilRequestProcessed(
1351 int32_t requestId, nsecs_t timeout) {
1352 Mutex::Autolock l(mLatestRequestMutex);
1353 status_t res;
1354 while (mLatestRequestId != requestId) {
1355 nsecs_t startTime = systemTime();
1356
1357 res = mLatestRequestSignal.waitRelative(mLatestRequestMutex, timeout);
1358 if (res != OK) return res;
1359
1360 timeout -= (systemTime() - startTime);
1361 }
1362
1363 return OK;
1364}
1365
1366
1367
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001368bool Camera3Device::RequestThread::threadLoop() {
1369
1370 status_t res;
1371
1372 // Handle paused state.
1373 if (waitIfPaused()) {
1374 return true;
1375 }
1376
1377 // Get work to do
1378
1379 sp<CaptureRequest> nextRequest = waitForNextRequest();
1380 if (nextRequest == NULL) {
1381 return true;
1382 }
1383
1384 // Create request to HAL
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001385 camera3_capture_request_t request = camera3_capture_request_t();
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001386 Vector<camera3_stream_buffer_t> outputBuffers;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001387
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001388 // Insert any queued triggers (before metadata is locked)
1389 int32_t triggerCount;
1390 res = insertTriggers(nextRequest);
1391 if (res < 0) {
1392 ALOGE("RequestThread: Unable to insert triggers "
1393 "(capture request %d, HAL device: %s (%d)",
1394 (mFrameNumber+1), strerror(-res), res);
1395 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1396 return false;
1397 }
1398 triggerCount = res;
1399
1400 bool triggersMixedIn = (triggerCount > 0 || mPrevTriggers > 0);
1401
1402 // If the request is the same as last, or we had triggers last time
1403 if (mPrevRequest != nextRequest || triggersMixedIn) {
1404 /**
1405 * The request should be presorted so accesses in HAL
1406 * are O(logn). Sidenote, sorting a sorted metadata is nop.
1407 */
1408 nextRequest->mSettings.sort();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001409 request.settings = nextRequest->mSettings.getAndLock();
1410 mPrevRequest = nextRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001411 ALOGVV("%s: Request settings are NEW", __FUNCTION__);
1412
1413 IF_ALOGV() {
1414 camera_metadata_ro_entry_t e = camera_metadata_ro_entry_t();
1415 find_camera_metadata_ro_entry(
1416 request.settings,
1417 ANDROID_CONTROL_AF_TRIGGER,
1418 &e
1419 );
1420 if (e.count > 0) {
1421 ALOGV("%s: Request (frame num %d) had AF trigger 0x%x",
1422 __FUNCTION__,
1423 mFrameNumber+1,
1424 e.data.u8[0]);
1425 }
1426 }
1427 } else {
1428 // leave request.settings NULL to indicate 'reuse latest given'
1429 ALOGVV("%s: Request settings are REUSED",
1430 __FUNCTION__);
1431 }
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001432
1433 camera3_stream_buffer_t inputBuffer;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001434
1435 // Fill in buffers
1436
1437 if (nextRequest->mInputStream != NULL) {
1438 request.input_buffer = &inputBuffer;
Igor Murashkin5a269fa2013-04-15 14:59:22 -07001439 res = nextRequest->mInputStream->getInputBuffer(&inputBuffer);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001440 if (res != OK) {
1441 ALOGE("RequestThread: Can't get input buffer, skipping request:"
1442 " %s (%d)", strerror(-res), res);
1443 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1444 return true;
1445 }
1446 } else {
1447 request.input_buffer = NULL;
1448 }
1449
1450 outputBuffers.insertAt(camera3_stream_buffer_t(), 0,
1451 nextRequest->mOutputStreams.size());
1452 request.output_buffers = outputBuffers.array();
1453 for (size_t i = 0; i < nextRequest->mOutputStreams.size(); i++) {
1454 res = nextRequest->mOutputStreams.editItemAt(i)->
1455 getBuffer(&outputBuffers.editItemAt(i));
1456 if (res != OK) {
1457 ALOGE("RequestThread: Can't get output buffer, skipping request:"
1458 "%s (%d)", strerror(-res), res);
1459 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1460 return true;
1461 }
1462 request.num_output_buffers++;
1463 }
1464
1465 request.frame_number = mFrameNumber++;
1466
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001467
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001468 // Submit request and block until ready for next one
1469
1470 res = mHal3Device->ops->process_capture_request(mHal3Device, &request);
1471 if (res != OK) {
1472 ALOGE("RequestThread: Unable to submit capture request %d to HAL"
1473 " device: %s (%d)", request.frame_number, strerror(-res), res);
1474 cleanUpFailedRequest(request, nextRequest, outputBuffers);
1475 return false;
1476 }
1477
1478 if (request.settings != NULL) {
1479 nextRequest->mSettings.unlock(request.settings);
1480 }
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001481
1482 // Remove any previously queued triggers (after unlock)
1483 res = removeTriggers(mPrevRequest);
1484 if (res != OK) {
1485 ALOGE("RequestThread: Unable to remove triggers "
1486 "(capture request %d, HAL device: %s (%d)",
1487 request.frame_number, strerror(-res), res);
1488 return false;
1489 }
1490 mPrevTriggers = triggerCount;
1491
1492 // Read android.request.id from the request settings metadata
1493 // - inform waitUntilRequestProcessed thread of a new request ID
1494 {
1495 Mutex::Autolock al(mLatestRequestMutex);
1496
1497 camera_metadata_entry_t requestIdEntry =
1498 nextRequest->mSettings.find(ANDROID_REQUEST_ID);
1499 if (requestIdEntry.count > 0) {
1500 mLatestRequestId = requestIdEntry.data.i32[0];
1501 } else {
1502 ALOGW("%s: Did not have android.request.id set in the request",
1503 __FUNCTION__);
1504 mLatestRequestId = NAME_NOT_FOUND;
1505 }
1506
1507 mLatestRequestSignal.signal();
1508 }
1509
Igor Murashkin5a269fa2013-04-15 14:59:22 -07001510 // Return input buffer back to framework
1511 if (request.input_buffer != NULL) {
1512 Camera3Stream *stream =
1513 Camera3Stream::cast(request.input_buffer->stream);
1514 res = stream->returnInputBuffer(*(request.input_buffer));
1515 // Note: stream may be deallocated at this point, if this buffer was the
1516 // last reference to it.
1517 if (res != OK) {
1518 ALOGE("%s: RequestThread: Can't return input buffer for frame %d to"
1519 " its stream:%s (%d)", __FUNCTION__,
1520 request.frame_number, strerror(-res), res);
1521 // TODO: Report error upstream
1522 }
1523 }
1524
1525
1526
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001527 return true;
1528}
1529
1530void Camera3Device::RequestThread::cleanUpFailedRequest(
1531 camera3_capture_request_t &request,
1532 sp<CaptureRequest> &nextRequest,
1533 Vector<camera3_stream_buffer_t> &outputBuffers) {
1534
1535 if (request.settings != NULL) {
1536 nextRequest->mSettings.unlock(request.settings);
1537 }
1538 if (request.input_buffer != NULL) {
1539 request.input_buffer->status = CAMERA3_BUFFER_STATUS_ERROR;
Igor Murashkin5a269fa2013-04-15 14:59:22 -07001540 nextRequest->mInputStream->returnInputBuffer(*(request.input_buffer));
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001541 }
1542 for (size_t i = 0; i < request.num_output_buffers; i++) {
1543 outputBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
1544 nextRequest->mOutputStreams.editItemAt(i)->returnBuffer(
1545 outputBuffers[i], 0);
1546 }
1547 // TODO: Report error upstream
1548}
1549
1550sp<Camera3Device::CaptureRequest>
1551 Camera3Device::RequestThread::waitForNextRequest() {
1552 status_t res;
1553 sp<CaptureRequest> nextRequest;
1554
1555 // Optimized a bit for the simple steady-state case (single repeating
1556 // request), to avoid putting that request in the queue temporarily.
1557 Mutex::Autolock l(mRequestLock);
1558
1559 while (mRequestQueue.empty()) {
1560 if (!mRepeatingRequests.empty()) {
1561 // Always atomically enqueue all requests in a repeating request
1562 // list. Guarantees a complete in-sequence set of captures to
1563 // application.
1564 const RequestList &requests = mRepeatingRequests;
1565 RequestList::const_iterator firstRequest =
1566 requests.begin();
1567 nextRequest = *firstRequest;
1568 mRequestQueue.insert(mRequestQueue.end(),
1569 ++firstRequest,
1570 requests.end());
1571 // No need to wait any longer
1572 break;
1573 }
1574
1575 res = mRequestSignal.waitRelative(mRequestLock, kRequestTimeout);
1576
1577 if (res == TIMED_OUT) {
1578 // Signal that we're paused by starvation
1579 Mutex::Autolock pl(mPauseLock);
1580 if (mPaused == false) {
1581 mPaused = true;
1582 mPausedSignal.signal();
1583 }
1584 // Stop waiting for now and let thread management happen
1585 return NULL;
1586 }
1587 }
1588
1589 if (nextRequest == NULL) {
1590 // Don't have a repeating request already in hand, so queue
1591 // must have an entry now.
1592 RequestList::iterator firstRequest =
1593 mRequestQueue.begin();
1594 nextRequest = *firstRequest;
1595 mRequestQueue.erase(firstRequest);
1596 }
1597
1598 // Not paused
1599 Mutex::Autolock pl(mPauseLock);
1600 mPaused = false;
1601
1602 // Check if we've reconfigured since last time, and reset the preview
1603 // request if so. Can't use 'NULL request == repeat' across configure calls.
1604 if (mReconfigured) {
1605 mPrevRequest.clear();
1606 mReconfigured = false;
1607 }
1608
1609 return nextRequest;
1610}
1611
1612bool Camera3Device::RequestThread::waitIfPaused() {
1613 status_t res;
1614 Mutex::Autolock l(mPauseLock);
1615 while (mDoPause) {
1616 // Signal that we're paused by request
1617 if (mPaused == false) {
1618 mPaused = true;
1619 mPausedSignal.signal();
1620 }
1621 res = mDoPauseSignal.waitRelative(mPauseLock, kRequestTimeout);
1622 if (res == TIMED_OUT) {
1623 return true;
1624 }
1625 }
1626 // We don't set mPaused to false here, because waitForNextRequest needs
1627 // to further manage the paused state in case of starvation.
1628 return false;
1629}
1630
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001631status_t Camera3Device::RequestThread::insertTriggers(
1632 const sp<CaptureRequest> &request) {
1633
1634 Mutex::Autolock al(mTriggerMutex);
1635
1636 CameraMetadata &metadata = request->mSettings;
1637 size_t count = mTriggerMap.size();
1638
1639 for (size_t i = 0; i < count; ++i) {
1640 RequestTrigger trigger = mTriggerMap.valueAt(i);
1641
1642 uint32_t tag = trigger.metadataTag;
1643 camera_metadata_entry entry = metadata.find(tag);
1644
1645 if (entry.count > 0) {
1646 /**
1647 * Already has an entry for this trigger in the request.
1648 * Rewrite it with our requested trigger value.
1649 */
1650 RequestTrigger oldTrigger = trigger;
1651
1652 oldTrigger.entryValue = entry.data.u8[0];
1653
1654 mTriggerReplacedMap.add(tag, oldTrigger);
1655 } else {
1656 /**
1657 * More typical, no trigger entry, so we just add it
1658 */
1659 mTriggerRemovedMap.add(tag, trigger);
1660 }
1661
1662 status_t res;
1663
1664 switch (trigger.getTagType()) {
1665 case TYPE_BYTE: {
1666 uint8_t entryValue = static_cast<uint8_t>(trigger.entryValue);
1667 res = metadata.update(tag,
1668 &entryValue,
1669 /*count*/1);
1670 break;
1671 }
1672 case TYPE_INT32:
1673 res = metadata.update(tag,
1674 &trigger.entryValue,
1675 /*count*/1);
1676 break;
1677 default:
1678 ALOGE("%s: Type not supported: 0x%x",
1679 __FUNCTION__,
1680 trigger.getTagType());
1681 return INVALID_OPERATION;
1682 }
1683
1684 if (res != OK) {
1685 ALOGE("%s: Failed to update request metadata with trigger tag %s"
1686 ", value %d", __FUNCTION__, trigger.getTagName(),
1687 trigger.entryValue);
1688 return res;
1689 }
1690
1691 ALOGV("%s: Mixed in trigger %s, value %d", __FUNCTION__,
1692 trigger.getTagName(),
1693 trigger.entryValue);
1694 }
1695
1696 mTriggerMap.clear();
1697
1698 return count;
1699}
1700
1701status_t Camera3Device::RequestThread::removeTriggers(
1702 const sp<CaptureRequest> &request) {
1703 Mutex::Autolock al(mTriggerMutex);
1704
1705 CameraMetadata &metadata = request->mSettings;
1706
1707 /**
1708 * Replace all old entries with their old values.
1709 */
1710 for (size_t i = 0; i < mTriggerReplacedMap.size(); ++i) {
1711 RequestTrigger trigger = mTriggerReplacedMap.valueAt(i);
1712
1713 status_t res;
1714
1715 uint32_t tag = trigger.metadataTag;
1716 switch (trigger.getTagType()) {
1717 case TYPE_BYTE: {
1718 uint8_t entryValue = static_cast<uint8_t>(trigger.entryValue);
1719 res = metadata.update(tag,
1720 &entryValue,
1721 /*count*/1);
1722 break;
1723 }
1724 case TYPE_INT32:
1725 res = metadata.update(tag,
1726 &trigger.entryValue,
1727 /*count*/1);
1728 break;
1729 default:
1730 ALOGE("%s: Type not supported: 0x%x",
1731 __FUNCTION__,
1732 trigger.getTagType());
1733 return INVALID_OPERATION;
1734 }
1735
1736 if (res != OK) {
1737 ALOGE("%s: Failed to restore request metadata with trigger tag %s"
1738 ", trigger value %d", __FUNCTION__,
1739 trigger.getTagName(), trigger.entryValue);
1740 return res;
1741 }
1742 }
1743 mTriggerReplacedMap.clear();
1744
1745 /**
1746 * Remove all new entries.
1747 */
1748 for (size_t i = 0; i < mTriggerRemovedMap.size(); ++i) {
1749 RequestTrigger trigger = mTriggerRemovedMap.valueAt(i);
1750 status_t res = metadata.erase(trigger.metadataTag);
1751
1752 if (res != OK) {
1753 ALOGE("%s: Failed to erase metadata with trigger tag %s"
1754 ", trigger value %d", __FUNCTION__,
1755 trigger.getTagName(), trigger.entryValue);
1756 return res;
1757 }
1758 }
1759 mTriggerRemovedMap.clear();
1760
1761 return OK;
1762}
1763
1764
1765
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001766/**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001767 * Static callback forwarding methods from HAL to instance
1768 */
1769
1770void Camera3Device::sProcessCaptureResult(const camera3_callback_ops *cb,
1771 const camera3_capture_result *result) {
1772 Camera3Device *d =
1773 const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb));
1774 d->processCaptureResult(result);
1775}
1776
1777void Camera3Device::sNotify(const camera3_callback_ops *cb,
1778 const camera3_notify_msg *msg) {
1779 Camera3Device *d =
1780 const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb));
1781 d->notify(msg);
1782}
1783
1784}; // namespace android