2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Contains implementation of a class EmulatedFakeCamera2 that encapsulates
19 * functionality of an advanced fake camera.
24 //#define LOG_NDEBUG 0
25 #define LOG_TAG "EmulatedCamera_FakeCamera2"
26 #include <utils/Log.h>
28 #include "EmulatedFakeCamera2.h"
29 #include "EmulatedCameraFactory.h"
31 #include <ui/GraphicBufferMapper.h>
32 #include "gralloc_cb.h"
34 #define ERROR_CAMERA_NOT_PRESENT -EPIPE
36 #define CAMERA2_EXT_TRIGGER_TESTING_DISCONNECT 0xFFFFFFFF
40 const int64_t USEC = 1000LL;
41 const int64_t MSEC = USEC * 1000LL;
42 const int64_t SEC = MSEC * 1000LL;
44 const uint32_t EmulatedFakeCamera2::kAvailableFormats[4] = {
45 HAL_PIXEL_FORMAT_RAW16,
46 HAL_PIXEL_FORMAT_BLOB,
47 HAL_PIXEL_FORMAT_RGBA_8888,
48 // HAL_PIXEL_FORMAT_YV12,
49 HAL_PIXEL_FORMAT_YCrCb_420_SP
52 const uint32_t EmulatedFakeCamera2::kAvailableRawSizes[2] = {
54 // Sensor::kResolution[0], Sensor::kResolution[1]
57 const uint64_t EmulatedFakeCamera2::kAvailableRawMinDurations[1] = {
58 static_cast<uint64_t>(Sensor::kFrameDurationRange[0])
61 const uint32_t EmulatedFakeCamera2::kAvailableProcessedSizesBack[4] = {
63 // Sensor::kResolution[0], Sensor::kResolution[1]
66 const uint32_t EmulatedFakeCamera2::kAvailableProcessedSizesFront[4] = {
68 // Sensor::kResolution[0], Sensor::kResolution[1]
71 const uint64_t EmulatedFakeCamera2::kAvailableProcessedMinDurations[1] = {
72 static_cast<uint64_t>(Sensor::kFrameDurationRange[0])
75 const uint32_t EmulatedFakeCamera2::kAvailableJpegSizesBack[2] = {
77 // Sensor::kResolution[0], Sensor::kResolution[1]
80 const uint32_t EmulatedFakeCamera2::kAvailableJpegSizesFront[2] = {
82 // Sensor::kResolution[0], Sensor::kResolution[1]
86 const uint64_t EmulatedFakeCamera2::kAvailableJpegMinDurations[1] = {
87 static_cast<uint64_t>(Sensor::kFrameDurationRange[0])
91 EmulatedFakeCamera2::EmulatedFakeCamera2(int cameraId,
93 struct hw_module_t* module)
94 : EmulatedCamera2(cameraId,module),
95 mFacingBack(facingBack),
98 ALOGD("Constructing emulated fake camera 2 facing %s",
99 facingBack ? "back" : "front");
102 EmulatedFakeCamera2::~EmulatedFakeCamera2() {
103 if (mCameraInfo != NULL) {
104 free_camera_metadata(mCameraInfo);
108 /****************************************************************************
109 * Public API overrides
110 ***************************************************************************/
112 status_t EmulatedFakeCamera2::Initialize() {
115 res = constructStaticInfo(&mCameraInfo, true);
117 ALOGE("%s: Unable to allocate static info: %s (%d)",
118 __FUNCTION__, strerror(-res), res);
121 res = constructStaticInfo(&mCameraInfo, false);
123 ALOGE("%s: Unable to fill in static info: %s (%d)",
124 __FUNCTION__, strerror(-res), res);
127 if (res != OK) return res;
130 mNextReprocessStreamId = 1;
132 mProcessedStreamCount = 0;
133 mJpegStreamCount = 0;
134 mReprocessStreamCount = 0;
139 /****************************************************************************
140 * Camera module API overrides
141 ***************************************************************************/
143 status_t EmulatedFakeCamera2::connectCamera(hw_device_t** device) {
145 ALOGV("%s", __FUNCTION__);
148 Mutex::Autolock l(mMutex);
149 if (!mStatusPresent) {
150 ALOGE("%s: Camera ID %d is unplugged", __FUNCTION__,
156 mConfigureThread = new ConfigureThread(this);
157 mReadoutThread = new ReadoutThread(this);
158 mControlThread = new ControlThread(this);
159 mSensor = new Sensor();
160 mJpegCompressor = new JpegCompressor();
163 mNextReprocessStreamId = 1;
165 res = mSensor->startUp();
166 if (res != NO_ERROR) return res;
168 res = mConfigureThread->run("EmulatedFakeCamera2::configureThread");
169 if (res != NO_ERROR) return res;
171 res = mReadoutThread->run("EmulatedFakeCamera2::readoutThread");
172 if (res != NO_ERROR) return res;
174 res = mControlThread->run("EmulatedFakeCamera2::controlThread");
175 if (res != NO_ERROR) return res;
177 status_t ret = EmulatedCamera2::connectCamera(device);
186 status_t EmulatedFakeCamera2::plugCamera() {
188 Mutex::Autolock l(mMutex);
190 if (!mStatusPresent) {
191 ALOGI("%s: Plugged back in", __FUNCTION__);
192 mStatusPresent = true;
199 status_t EmulatedFakeCamera2::unplugCamera() {
201 Mutex::Autolock l(mMutex);
203 if (mStatusPresent) {
204 ALOGI("%s: Unplugged camera", __FUNCTION__);
205 mStatusPresent = false;
209 return closeCamera();
212 camera_device_status_t EmulatedFakeCamera2::getHotplugStatus() {
213 Mutex::Autolock l(mMutex);
214 return mStatusPresent ?
215 CAMERA_DEVICE_STATUS_PRESENT :
216 CAMERA_DEVICE_STATUS_NOT_PRESENT;
221 status_t EmulatedFakeCamera2::closeCamera() {
223 Mutex::Autolock l(mMutex);
226 ALOGV("%s", __FUNCTION__);
232 res = mSensor->shutDown();
233 if (res != NO_ERROR) {
234 ALOGE("%s: Unable to shut down sensor: %d", __FUNCTION__, res);
238 mConfigureThread->requestExit();
239 mReadoutThread->requestExit();
240 mControlThread->requestExit();
241 mJpegCompressor->cancel();
244 // give up the lock since we will now block and the threads
245 // can call back into this object
246 mConfigureThread->join();
247 mReadoutThread->join();
248 mControlThread->join();
250 ALOGV("%s exit", __FUNCTION__);
253 Mutex::Autolock l(mMutex);
254 mIsConnected = false;
260 status_t EmulatedFakeCamera2::getCameraInfo(struct camera_info *info) {
261 info->facing = mFacingBack ? CAMERA_FACING_BACK : CAMERA_FACING_FRONT;
262 info->orientation = gEmulatedCameraFactory.getFakeCameraOrientation();
263 return EmulatedCamera2::getCameraInfo(info);
266 /****************************************************************************
267 * Camera device API overrides
268 ***************************************************************************/
270 /** Request input queue */
272 int EmulatedFakeCamera2::requestQueueNotify() {
273 ALOGV("Request queue notification received");
275 ALOG_ASSERT(mRequestQueueSrc != NULL,
276 "%s: Request queue src not set, but received queue notification!",
278 ALOG_ASSERT(mFrameQueueDst != NULL,
279 "%s: Request queue src not set, but received queue notification!",
281 ALOG_ASSERT(mStreams.size() != 0,
282 "%s: No streams allocated, but received queue notification!",
284 return mConfigureThread->newRequestAvailable();
287 int EmulatedFakeCamera2::getInProgressCount() {
288 Mutex::Autolock l(mMutex);
290 if (!mStatusPresent) {
291 ALOGW("%s: Camera was physically disconnected", __FUNCTION__);
292 return ERROR_CAMERA_NOT_PRESENT;
295 int requestCount = 0;
296 requestCount += mConfigureThread->getInProgressCount();
297 requestCount += mReadoutThread->getInProgressCount();
298 requestCount += mJpegCompressor->isBusy() ? 1 : 0;
303 int EmulatedFakeCamera2::constructDefaultRequest(
304 int request_template,
305 camera_metadata_t **request) {
307 if (request == NULL) return BAD_VALUE;
308 if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) {
313 Mutex::Autolock l(mMutex);
314 if (!mStatusPresent) {
315 ALOGW("%s: Camera was physically disconnected", __FUNCTION__);
316 return ERROR_CAMERA_NOT_PRESENT;
321 // Pass 1, calculate size and allocate
322 res = constructDefaultRequest(request_template,
328 // Pass 2, build request
329 res = constructDefaultRequest(request_template,
333 ALOGE("Unable to populate new request for template %d",
340 int EmulatedFakeCamera2::allocateStream(
344 const camera2_stream_ops_t *stream_ops,
346 uint32_t *format_actual,
348 uint32_t *max_buffers) {
349 Mutex::Autolock l(mMutex);
351 if (!mStatusPresent) {
352 ALOGW("%s: Camera was physically disconnected", __FUNCTION__);
353 return ERROR_CAMERA_NOT_PRESENT;
356 // Temporary shim until FORMAT_ZSL is removed
357 if (format == CAMERA2_HAL_PIXEL_FORMAT_ZSL) {
358 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
361 if (format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
362 unsigned int numFormats = sizeof(kAvailableFormats) / sizeof(uint32_t);
363 unsigned int formatIdx = 0;
364 unsigned int sizeOffsetIdx = 0;
365 for (; formatIdx < numFormats; formatIdx++) {
366 if (format == (int)kAvailableFormats[formatIdx]) break;
368 if (formatIdx == numFormats) {
369 ALOGE("%s: Format 0x%x is not supported", __FUNCTION__, format);
374 const uint32_t *availableSizes;
375 size_t availableSizeCount;
377 case HAL_PIXEL_FORMAT_RAW16:
378 availableSizes = kAvailableRawSizes;
379 availableSizeCount = sizeof(kAvailableRawSizes)/sizeof(uint32_t);
381 case HAL_PIXEL_FORMAT_BLOB:
382 availableSizes = mFacingBack ?
383 kAvailableJpegSizesBack : kAvailableJpegSizesFront;
384 availableSizeCount = mFacingBack ?
385 sizeof(kAvailableJpegSizesBack)/sizeof(uint32_t) :
386 sizeof(kAvailableJpegSizesFront)/sizeof(uint32_t);
388 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
389 case HAL_PIXEL_FORMAT_RGBA_8888:
390 case HAL_PIXEL_FORMAT_YV12:
391 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
392 availableSizes = mFacingBack ?
393 kAvailableProcessedSizesBack : kAvailableProcessedSizesFront;
394 availableSizeCount = mFacingBack ?
395 sizeof(kAvailableProcessedSizesBack)/sizeof(uint32_t) :
396 sizeof(kAvailableProcessedSizesFront)/sizeof(uint32_t);
399 ALOGE("%s: Unknown format 0x%x", __FUNCTION__, format);
403 unsigned int resIdx = 0;
404 for (; resIdx < availableSizeCount; resIdx++) {
405 if (availableSizes[resIdx * 2] == width &&
406 availableSizes[resIdx * 2 + 1] == height) break;
408 if (resIdx == availableSizeCount) {
409 ALOGE("%s: Format 0x%x does not support resolution %d, %d", __FUNCTION__,
410 format, width, height);
415 case HAL_PIXEL_FORMAT_RAW16:
416 if (mRawStreamCount >= kMaxRawStreamCount) {
417 ALOGE("%s: Cannot allocate another raw stream (%d already allocated)",
418 __FUNCTION__, mRawStreamCount);
419 return INVALID_OPERATION;
423 case HAL_PIXEL_FORMAT_BLOB:
424 if (mJpegStreamCount >= kMaxJpegStreamCount) {
425 ALOGE("%s: Cannot allocate another JPEG stream (%d already allocated)",
426 __FUNCTION__, mJpegStreamCount);
427 return INVALID_OPERATION;
432 if (mProcessedStreamCount >= kMaxProcessedStreamCount) {
433 ALOGE("%s: Cannot allocate another processed stream (%d already allocated)",
434 __FUNCTION__, mProcessedStreamCount);
435 return INVALID_OPERATION;
437 mProcessedStreamCount++;
441 newStream.ops = stream_ops;
442 newStream.width = width;
443 newStream.height = height;
444 newStream.format = format;
445 // TODO: Query stride from gralloc
446 newStream.stride = width;
448 mStreams.add(mNextStreamId, newStream);
450 *stream_id = mNextStreamId;
451 if (format_actual) *format_actual = format;
452 *usage = GRALLOC_USAGE_HW_CAMERA_WRITE;
453 *max_buffers = kMaxBufferCount;
455 ALOGV("Stream allocated: %d, %d x %d, 0x%x. U: %x, B: %d",
456 *stream_id, width, height, format, *usage, *max_buffers);
462 int EmulatedFakeCamera2::registerStreamBuffers(
465 buffer_handle_t *buffers) {
466 Mutex::Autolock l(mMutex);
468 if (!mStatusPresent) {
469 ALOGW("%s: Camera was physically disconnected", __FUNCTION__);
470 return ERROR_CAMERA_NOT_PRESENT;
473 ALOGV("%s: Stream %d registering %d buffers", __FUNCTION__,
474 stream_id, num_buffers);
475 // Need to find out what the final concrete pixel format for our stream is
476 // Assumes that all buffers have the same format.
477 if (num_buffers < 1) {
478 ALOGE("%s: Stream %d only has %d buffers!",
479 __FUNCTION__, stream_id, num_buffers);
482 const cb_handle_t *streamBuffer =
483 reinterpret_cast<const cb_handle_t*>(buffers[0]);
485 int finalFormat = streamBuffer->format;
487 if (finalFormat == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
488 ALOGE("%s: Stream %d: Bad final pixel format "
489 "HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; "
490 "concrete pixel format required!", __FUNCTION__, stream_id);
494 ssize_t streamIndex = mStreams.indexOfKey(stream_id);
495 if (streamIndex < 0) {
496 ALOGE("%s: Unknown stream id %d!", __FUNCTION__, stream_id);
500 Stream &stream = mStreams.editValueAt(streamIndex);
502 ALOGV("%s: Stream %d format set to %x, previously %x",
503 __FUNCTION__, stream_id, finalFormat, stream.format);
505 stream.format = finalFormat;
510 int EmulatedFakeCamera2::releaseStream(uint32_t stream_id) {
511 Mutex::Autolock l(mMutex);
513 ssize_t streamIndex = mStreams.indexOfKey(stream_id);
514 if (streamIndex < 0) {
515 ALOGE("%s: Unknown stream id %d!", __FUNCTION__, stream_id);
519 if (isStreamInUse(stream_id)) {
520 ALOGE("%s: Cannot release stream %d; in use!", __FUNCTION__,
525 switch(mStreams.valueAt(streamIndex).format) {
526 case HAL_PIXEL_FORMAT_RAW16:
529 case HAL_PIXEL_FORMAT_BLOB:
533 mProcessedStreamCount--;
537 mStreams.removeItemsAt(streamIndex);
542 int EmulatedFakeCamera2::allocateReprocessStreamFromStream(
543 uint32_t output_stream_id,
544 const camera2_stream_in_ops_t *stream_ops,
545 uint32_t *stream_id) {
546 Mutex::Autolock l(mMutex);
548 if (!mStatusPresent) {
549 ALOGW("%s: Camera was physically disconnected", __FUNCTION__);
550 return ERROR_CAMERA_NOT_PRESENT;
553 ssize_t baseStreamIndex = mStreams.indexOfKey(output_stream_id);
554 if (baseStreamIndex < 0) {
555 ALOGE("%s: Unknown output stream id %d!", __FUNCTION__, output_stream_id);
559 const Stream &baseStream = mStreams[baseStreamIndex];
561 // We'll reprocess anything we produced
563 if (mReprocessStreamCount >= kMaxReprocessStreamCount) {
564 ALOGE("%s: Cannot allocate another reprocess stream (%d already allocated)",
565 __FUNCTION__, mReprocessStreamCount);
566 return INVALID_OPERATION;
568 mReprocessStreamCount++;
570 ReprocessStream newStream;
571 newStream.ops = stream_ops;
572 newStream.width = baseStream.width;
573 newStream.height = baseStream.height;
574 newStream.format = baseStream.format;
575 newStream.stride = baseStream.stride;
576 newStream.sourceStreamId = output_stream_id;
578 *stream_id = mNextReprocessStreamId;
579 mReprocessStreams.add(mNextReprocessStreamId, newStream);
581 ALOGV("Reprocess stream allocated: %d: %d, %d, 0x%x. Parent stream: %d",
582 *stream_id, newStream.width, newStream.height, newStream.format,
585 mNextReprocessStreamId++;
589 int EmulatedFakeCamera2::releaseReprocessStream(uint32_t stream_id) {
590 Mutex::Autolock l(mMutex);
592 ssize_t streamIndex = mReprocessStreams.indexOfKey(stream_id);
593 if (streamIndex < 0) {
594 ALOGE("%s: Unknown reprocess stream id %d!", __FUNCTION__, stream_id);
598 if (isReprocessStreamInUse(stream_id)) {
599 ALOGE("%s: Cannot release reprocessing stream %d; in use!", __FUNCTION__,
604 mReprocessStreamCount--;
605 mReprocessStreams.removeItemsAt(streamIndex);
610 int EmulatedFakeCamera2::triggerAction(uint32_t trigger_id,
613 Mutex::Autolock l(mMutex);
615 if (trigger_id == CAMERA2_EXT_TRIGGER_TESTING_DISCONNECT) {
616 ALOGI("%s: Disconnect trigger - camera must be closed", __FUNCTION__);
617 mStatusPresent = false;
619 gEmulatedCameraFactory.onStatusChanged(
621 CAMERA_DEVICE_STATUS_NOT_PRESENT);
624 if (!mStatusPresent) {
625 ALOGW("%s: Camera was physically disconnected", __FUNCTION__);
626 return ERROR_CAMERA_NOT_PRESENT;
629 return mControlThread->triggerAction(trigger_id,
633 /** Shutdown and debug methods */
635 int EmulatedFakeCamera2::dump(int fd) {
638 result.appendFormat(" Camera HAL device: EmulatedFakeCamera2\n");
639 result.appendFormat(" Streams:\n");
640 for (size_t i = 0; i < mStreams.size(); i++) {
641 int id = mStreams.keyAt(i);
642 const Stream& s = mStreams.valueAt(i);
644 " Stream %d: %d x %d, format 0x%x, stride %d\n",
645 id, s.width, s.height, s.format, s.stride);
648 write(fd, result.string(), result.size());
653 void EmulatedFakeCamera2::signalError() {
654 // TODO: Let parent know so we can shut down cleanly
655 ALOGE("Worker thread is signaling a serious error");
658 /** Pipeline control worker thread methods */
660 EmulatedFakeCamera2::ConfigureThread::ConfigureThread(EmulatedFakeCamera2 *parent):
668 EmulatedFakeCamera2::ConfigureThread::~ConfigureThread() {
671 status_t EmulatedFakeCamera2::ConfigureThread::readyToRun() {
672 Mutex::Autolock lock(mInputMutex);
674 ALOGV("Starting up ConfigureThread");
679 mInputSignal.signal();
683 status_t EmulatedFakeCamera2::ConfigureThread::waitUntilRunning() {
684 Mutex::Autolock lock(mInputMutex);
686 ALOGV("Waiting for configure thread to start");
687 mInputSignal.wait(mInputMutex);
692 status_t EmulatedFakeCamera2::ConfigureThread::newRequestAvailable() {
695 Mutex::Autolock lock(mInputMutex);
698 mInputSignal.signal();
703 bool EmulatedFakeCamera2::ConfigureThread::isStreamInUse(uint32_t id) {
704 Mutex::Autolock lock(mInternalsMutex);
706 if (mNextBuffers == NULL) return false;
707 for (size_t i=0; i < mNextBuffers->size(); i++) {
708 if ((*mNextBuffers)[i].streamId == (int)id) return true;
713 int EmulatedFakeCamera2::ConfigureThread::getInProgressCount() {
714 Mutex::Autolock lock(mInputMutex);
715 return mRequestCount;
718 bool EmulatedFakeCamera2::ConfigureThread::threadLoop() {
721 // Check if we're currently processing or just waiting
723 Mutex::Autolock lock(mInputMutex);
725 // Inactive, keep waiting until we've been signaled
727 res = mInputSignal.waitRelative(mInputMutex, kWaitPerLoop);
728 if (res != NO_ERROR && res != TIMED_OUT) {
729 ALOGE("%s: Error waiting for input requests: %d",
733 if (!mActive) return true;
734 ALOGV("New request available");
739 if (mRequest == NULL) {
740 Mutex::Autolock il(mInternalsMutex);
742 ALOGV("Configure: Getting next request");
743 res = mParent->mRequestQueueSrc->dequeue_request(
744 mParent->mRequestQueueSrc,
746 if (res != NO_ERROR) {
747 ALOGE("%s: Error dequeuing next request: %d", __FUNCTION__, res);
748 mParent->signalError();
751 if (mRequest == NULL) {
752 ALOGV("Configure: Request queue empty, going inactive");
753 // No requests available, go into inactive mode
754 Mutex::Autolock lock(mInputMutex);
758 Mutex::Autolock lock(mInputMutex);
762 camera_metadata_entry_t type;
763 res = find_camera_metadata_entry(mRequest,
764 ANDROID_REQUEST_TYPE,
766 if (res != NO_ERROR) {
767 ALOGE("%s: error reading request type", __FUNCTION__);
768 mParent->signalError();
771 bool success = false;;
772 switch (type.data.u8[0]) {
773 case ANDROID_REQUEST_TYPE_CAPTURE:
774 success = setupCapture();
776 case ANDROID_REQUEST_TYPE_REPROCESS:
777 success = setupReprocess();
780 ALOGE("%s: Unexpected request type %d",
781 __FUNCTION__, type.data.u8[0]);
782 mParent->signalError();
785 if (!success) return false;
789 if (mWaitingForReadout) {
791 readoutDone = mParent->mReadoutThread->waitForReady(kWaitPerLoop);
792 if (!readoutDone) return true;
794 if (mNextNeedsJpeg) {
795 ALOGV("Configure: Waiting for JPEG compressor");
797 ALOGV("Configure: Waiting for sensor");
799 mWaitingForReadout = false;
802 if (mNextNeedsJpeg) {
804 jpegDone = mParent->mJpegCompressor->waitForDone(kWaitPerLoop);
805 if (!jpegDone) return true;
807 ALOGV("Configure: Waiting for sensor");
808 mNextNeedsJpeg = false;
811 if (mNextIsCapture) {
812 return configureNextCapture();
814 return configureNextReprocess();
818 bool EmulatedFakeCamera2::ConfigureThread::setupCapture() {
821 mNextIsCapture = true;
822 // Get necessary parameters for sensor config
823 mParent->mControlThread->processRequest(mRequest);
825 camera_metadata_entry_t streams;
826 res = find_camera_metadata_entry(mRequest,
827 ANDROID_REQUEST_OUTPUT_STREAMS,
829 if (res != NO_ERROR) {
830 ALOGE("%s: error reading output stream tag", __FUNCTION__);
831 mParent->signalError();
835 mNextBuffers = new Buffers;
836 mNextNeedsJpeg = false;
837 ALOGV("Configure: Setting up buffers for capture");
838 for (size_t i = 0; i < streams.count; i++) {
839 int streamId = streams.data.i32[i];
840 const Stream &s = mParent->getStreamInfo(streamId);
841 if (s.format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
842 ALOGE("%s: Stream %d does not have a concrete pixel format, but "
843 "is included in a request!", __FUNCTION__, streamId);
844 mParent->signalError();
848 b.streamId = streams.data.u8[i];
853 mNextBuffers->push_back(b);
854 ALOGV("Configure: Buffer %zu: Stream %d, %d x %d, format 0x%x, "
856 i, b.streamId, b.width, b.height, b.format, b.stride);
857 if (b.format == HAL_PIXEL_FORMAT_BLOB) {
858 mNextNeedsJpeg = true;
862 camera_metadata_entry_t e;
863 res = find_camera_metadata_entry(mRequest,
864 ANDROID_REQUEST_FRAME_COUNT,
866 if (res != NO_ERROR) {
867 ALOGE("%s: error reading frame count tag: %s (%d)",
868 __FUNCTION__, strerror(-res), res);
869 mParent->signalError();
872 mNextFrameNumber = *e.data.i32;
874 res = find_camera_metadata_entry(mRequest,
875 ANDROID_SENSOR_EXPOSURE_TIME,
877 if (res != NO_ERROR) {
878 ALOGE("%s: error reading exposure time tag: %s (%d)",
879 __FUNCTION__, strerror(-res), res);
880 mParent->signalError();
883 mNextExposureTime = *e.data.i64;
885 res = find_camera_metadata_entry(mRequest,
886 ANDROID_SENSOR_FRAME_DURATION,
888 if (res != NO_ERROR) {
889 ALOGE("%s: error reading frame duration tag", __FUNCTION__);
890 mParent->signalError();
893 mNextFrameDuration = *e.data.i64;
895 if (mNextFrameDuration <
896 mNextExposureTime + Sensor::kMinVerticalBlank) {
897 mNextFrameDuration = mNextExposureTime + Sensor::kMinVerticalBlank;
899 res = find_camera_metadata_entry(mRequest,
900 ANDROID_SENSOR_SENSITIVITY,
902 if (res != NO_ERROR) {
903 ALOGE("%s: error reading sensitivity tag", __FUNCTION__);
904 mParent->signalError();
907 mNextSensitivity = *e.data.i32;
909 // Start waiting on readout thread
910 mWaitingForReadout = true;
911 ALOGV("Configure: Waiting for readout thread");
916 bool EmulatedFakeCamera2::ConfigureThread::configureNextCapture() {
917 bool vsync = mParent->mSensor->waitForVSync(kWaitPerLoop);
918 if (!vsync) return true;
920 Mutex::Autolock il(mInternalsMutex);
921 ALOGV("Configure: Configuring sensor for capture %d", mNextFrameNumber);
922 mParent->mSensor->setExposureTime(mNextExposureTime);
923 mParent->mSensor->setFrameDuration(mNextFrameDuration);
924 mParent->mSensor->setSensitivity(mNextSensitivity);
928 ALOGV("Configure: Done configure for capture %d", mNextFrameNumber);
929 mParent->mReadoutThread->setNextOperation(true, mRequest, mNextBuffers);
930 mParent->mSensor->setDestinationBuffers(mNextBuffers);
935 Mutex::Autolock lock(mInputMutex);
941 bool EmulatedFakeCamera2::ConfigureThread::setupReprocess() {
944 mNextNeedsJpeg = true;
945 mNextIsCapture = false;
947 camera_metadata_entry_t reprocessStreams;
948 res = find_camera_metadata_entry(mRequest,
949 ANDROID_REQUEST_INPUT_STREAMS,
951 if (res != NO_ERROR) {
952 ALOGE("%s: error reading output stream tag", __FUNCTION__);
953 mParent->signalError();
957 mNextBuffers = new Buffers;
959 ALOGV("Configure: Setting up input buffers for reprocess");
960 for (size_t i = 0; i < reprocessStreams.count; i++) {
961 int streamId = reprocessStreams.data.i32[i];
962 const ReprocessStream &s = mParent->getReprocessStreamInfo(streamId);
963 if (s.format != HAL_PIXEL_FORMAT_RGB_888) {
964 ALOGE("%s: Only ZSL reprocessing supported!",
966 mParent->signalError();
970 b.streamId = -streamId;
975 mNextBuffers->push_back(b);
978 camera_metadata_entry_t streams;
979 res = find_camera_metadata_entry(mRequest,
980 ANDROID_REQUEST_OUTPUT_STREAMS,
982 if (res != NO_ERROR) {
983 ALOGE("%s: error reading output stream tag", __FUNCTION__);
984 mParent->signalError();
988 ALOGV("Configure: Setting up output buffers for reprocess");
989 for (size_t i = 0; i < streams.count; i++) {
990 int streamId = streams.data.i32[i];
991 const Stream &s = mParent->getStreamInfo(streamId);
992 if (s.format != HAL_PIXEL_FORMAT_BLOB) {
993 // TODO: Support reprocess to YUV
994 ALOGE("%s: Non-JPEG output stream %d for reprocess not supported",
995 __FUNCTION__, streamId);
996 mParent->signalError();
1000 b.streamId = streams.data.u8[i];
1002 b.height = s.height;
1003 b.format = s.format;
1004 b.stride = s.stride;
1005 mNextBuffers->push_back(b);
1006 ALOGV("Configure: Buffer %zu: Stream %d, %d x %d, format 0x%x, "
1008 i, b.streamId, b.width, b.height, b.format, b.stride);
1011 camera_metadata_entry_t e;
1012 res = find_camera_metadata_entry(mRequest,
1013 ANDROID_REQUEST_FRAME_COUNT,
1015 if (res != NO_ERROR) {
1016 ALOGE("%s: error reading frame count tag: %s (%d)",
1017 __FUNCTION__, strerror(-res), res);
1018 mParent->signalError();
1021 mNextFrameNumber = *e.data.i32;
1026 bool EmulatedFakeCamera2::ConfigureThread::configureNextReprocess() {
1027 Mutex::Autolock il(mInternalsMutex);
1031 ALOGV("Configure: Done configure for reprocess %d", mNextFrameNumber);
1032 mParent->mReadoutThread->setNextOperation(false, mRequest, mNextBuffers);
1035 mNextBuffers = NULL;
1037 Mutex::Autolock lock(mInputMutex);
1043 bool EmulatedFakeCamera2::ConfigureThread::getBuffers() {
1045 /** Get buffers to fill for this frame */
1046 for (size_t i = 0; i < mNextBuffers->size(); i++) {
1047 StreamBuffer &b = mNextBuffers->editItemAt(i);
1049 if (b.streamId > 0) {
1050 Stream s = mParent->getStreamInfo(b.streamId);
1051 ALOGV("Configure: Dequeing buffer from stream %d", b.streamId);
1052 res = s.ops->dequeue_buffer(s.ops, &(b.buffer) );
1053 if (res != NO_ERROR || b.buffer == NULL) {
1054 ALOGE("%s: Unable to dequeue buffer from stream %d: %s (%d)",
1055 __FUNCTION__, b.streamId, strerror(-res), res);
1056 mParent->signalError();
1060 /* Lock the buffer from the perspective of the graphics mapper */
1061 const Rect rect(s.width, s.height);
1063 res = GraphicBufferMapper::get().lock(*(b.buffer),
1064 GRALLOC_USAGE_HW_CAMERA_WRITE,
1065 rect, (void**)&(b.img) );
1067 if (res != NO_ERROR) {
1068 ALOGE("%s: grbuffer_mapper.lock failure: %s (%d)",
1069 __FUNCTION__, strerror(-res), res);
1070 s.ops->cancel_buffer(s.ops,
1072 mParent->signalError();
1076 ReprocessStream s = mParent->getReprocessStreamInfo(-b.streamId);
1077 ALOGV("Configure: Acquiring buffer from reprocess stream %d",
1079 res = s.ops->acquire_buffer(s.ops, &(b.buffer) );
1080 if (res != NO_ERROR || b.buffer == NULL) {
1081 ALOGE("%s: Unable to acquire buffer from reprocess stream %d: "
1082 "%s (%d)", __FUNCTION__, -b.streamId,
1083 strerror(-res), res);
1084 mParent->signalError();
1088 /* Lock the buffer from the perspective of the graphics mapper */
1089 const Rect rect(s.width, s.height);
1091 res = GraphicBufferMapper::get().lock(*(b.buffer),
1092 GRALLOC_USAGE_HW_CAMERA_READ,
1093 rect, (void**)&(b.img) );
1094 if (res != NO_ERROR) {
1095 ALOGE("%s: grbuffer_mapper.lock failure: %s (%d)",
1096 __FUNCTION__, strerror(-res), res);
1097 s.ops->release_buffer(s.ops,
1099 mParent->signalError();
1107 EmulatedFakeCamera2::ReadoutThread::ReadoutThread(EmulatedFakeCamera2 *parent):
1115 mInFlightQueue = new InFlightQueue[kInFlightQueueSize];
1120 EmulatedFakeCamera2::ReadoutThread::~ReadoutThread() {
1121 delete mInFlightQueue;
1124 status_t EmulatedFakeCamera2::ReadoutThread::readyToRun() {
1125 Mutex::Autolock lock(mInputMutex);
1126 ALOGV("Starting up ReadoutThread");
1128 mInputSignal.signal();
1132 status_t EmulatedFakeCamera2::ReadoutThread::waitUntilRunning() {
1133 Mutex::Autolock lock(mInputMutex);
1135 ALOGV("Waiting for readout thread to start");
1136 mInputSignal.wait(mInputMutex);
1141 bool EmulatedFakeCamera2::ReadoutThread::waitForReady(nsecs_t timeout) {
1143 Mutex::Autolock lock(mInputMutex);
1144 while (!readyForNextCapture()) {
1145 res = mReadySignal.waitRelative(mInputMutex, timeout);
1146 if (res == TIMED_OUT) return false;
1148 ALOGE("%s: Error waiting for ready: %s (%d)", __FUNCTION__,
1149 strerror(-res), res);
1156 bool EmulatedFakeCamera2::ReadoutThread::readyForNextCapture() {
1157 return (mInFlightTail + 1) % kInFlightQueueSize != mInFlightHead;
1160 void EmulatedFakeCamera2::ReadoutThread::setNextOperation(
1162 camera_metadata_t *request,
1164 Mutex::Autolock lock(mInputMutex);
1165 if ( !readyForNextCapture() ) {
1166 ALOGE("In flight queue full, dropping captures");
1167 mParent->signalError();
1170 mInFlightQueue[mInFlightTail].isCapture = isCapture;
1171 mInFlightQueue[mInFlightTail].request = request;
1172 mInFlightQueue[mInFlightTail].buffers = buffers;
1173 mInFlightTail = (mInFlightTail + 1) % kInFlightQueueSize;
1178 mInputSignal.signal();
1182 bool EmulatedFakeCamera2::ReadoutThread::isStreamInUse(uint32_t id) {
1183 // acquire in same order as threadLoop
1184 Mutex::Autolock iLock(mInternalsMutex);
1185 Mutex::Autolock lock(mInputMutex);
1187 size_t i = mInFlightHead;
1188 while (i != mInFlightTail) {
1189 for (size_t j = 0; j < mInFlightQueue[i].buffers->size(); j++) {
1190 if ( (*(mInFlightQueue[i].buffers))[j].streamId == (int)id )
1193 i = (i + 1) % kInFlightQueueSize;
1197 if (mBuffers != NULL) {
1198 for (i = 0; i < mBuffers->size(); i++) {
1199 if ( (*mBuffers)[i].streamId == (int)id) return true;
1206 int EmulatedFakeCamera2::ReadoutThread::getInProgressCount() {
1207 Mutex::Autolock lock(mInputMutex);
1209 return mRequestCount;
1212 bool EmulatedFakeCamera2::ReadoutThread::threadLoop() {
1213 static const nsecs_t kWaitPerLoop = 10000000L; // 10 ms
1215 int32_t frameNumber;
1217 // Check if we're currently processing or just waiting
1219 Mutex::Autolock lock(mInputMutex);
1221 // Inactive, keep waiting until we've been signaled
1222 res = mInputSignal.waitRelative(mInputMutex, kWaitPerLoop);
1223 if (res != NO_ERROR && res != TIMED_OUT) {
1224 ALOGE("%s: Error waiting for capture requests: %d",
1226 mParent->signalError();
1229 if (!mActive) return true;
1231 // Active, see if we need a new request
1232 if (mRequest == NULL) {
1233 if (mInFlightHead == mInFlightTail) {
1235 ALOGV("Waiting for sensor data");
1239 Mutex::Autolock iLock(mInternalsMutex);
1240 mReadySignal.signal();
1241 mIsCapture = mInFlightQueue[mInFlightHead].isCapture;
1242 mRequest = mInFlightQueue[mInFlightHead].request;
1243 mBuffers = mInFlightQueue[mInFlightHead].buffers;
1244 mInFlightQueue[mInFlightHead].request = NULL;
1245 mInFlightQueue[mInFlightHead].buffers = NULL;
1246 mInFlightHead = (mInFlightHead + 1) % kInFlightQueueSize;
1247 ALOGV("Ready to read out request %p, %zu buffers",
1248 mRequest, mBuffers->size());
1253 // Active with request, wait on sensor to complete
1255 nsecs_t captureTime;
1259 gotFrame = mParent->mSensor->waitForNewFrame(kWaitPerLoop,
1262 if (!gotFrame) return true;
1265 Mutex::Autolock iLock(mInternalsMutex);
1267 camera_metadata_entry_t entry;
1269 res = find_camera_metadata_entry(mRequest,
1270 ANDROID_SENSOR_TIMESTAMP,
1272 if (res != NO_ERROR) {
1273 ALOGE("%s: error reading reprocessing timestamp: %s (%d)",
1274 __FUNCTION__, strerror(-res), res);
1275 mParent->signalError();
1278 captureTime = entry.data.i64[0];
1281 res = find_camera_metadata_entry(mRequest,
1282 ANDROID_REQUEST_FRAME_COUNT,
1284 if (res != NO_ERROR) {
1285 ALOGE("%s: error reading frame count tag: %s (%d)",
1286 __FUNCTION__, strerror(-res), res);
1287 mParent->signalError();
1290 frameNumber = *entry.data.i32;
1292 res = find_camera_metadata_entry(mRequest,
1293 ANDROID_REQUEST_METADATA_MODE,
1295 if (res != NO_ERROR) {
1296 ALOGE("%s: error reading metadata mode tag: %s (%d)",
1297 __FUNCTION__, strerror(-res), res);
1298 mParent->signalError();
1302 // Got sensor data and request, construct frame and send it out
1303 ALOGV("Readout: Constructing metadata and frames for request %d",
1306 if (*entry.data.u8 == ANDROID_REQUEST_METADATA_MODE_FULL) {
1307 ALOGV("Readout: Metadata requested, constructing");
1309 camera_metadata_t *frame = NULL;
1311 size_t frame_entries = get_camera_metadata_entry_count(mRequest);
1312 size_t frame_data = get_camera_metadata_data_count(mRequest);
1314 // TODO: Dynamically calculate based on enabled statistics, etc
1315 frame_entries += 10;
1318 res = mParent->mFrameQueueDst->dequeue_frame(mParent->mFrameQueueDst,
1319 frame_entries, frame_data, &frame);
1321 if (res != NO_ERROR || frame == NULL) {
1322 ALOGE("%s: Unable to dequeue frame metadata buffer", __FUNCTION__);
1323 mParent->signalError();
1327 res = append_camera_metadata(frame, mRequest);
1328 if (res != NO_ERROR) {
1329 ALOGE("Unable to append request metadata");
1333 add_camera_metadata_entry(frame,
1334 ANDROID_SENSOR_TIMESTAMP,
1338 collectStatisticsMetadata(frame);
1339 // TODO: Collect all final values used from sensor in addition to timestamp
1342 ALOGV("Readout: Enqueue frame %d", frameNumber);
1343 mParent->mFrameQueueDst->enqueue_frame(mParent->mFrameQueueDst,
1346 ALOGV("Readout: Free request");
1347 res = mParent->mRequestQueueSrc->free_request(mParent->mRequestQueueSrc, mRequest);
1348 if (res != NO_ERROR) {
1349 ALOGE("%s: Unable to return request buffer to queue: %d",
1351 mParent->signalError();
1356 int compressedBufferIndex = -1;
1357 ALOGV("Readout: Processing %zu buffers", mBuffers->size());
1358 for (size_t i = 0; i < mBuffers->size(); i++) {
1359 const StreamBuffer &b = (*mBuffers)[i];
1360 ALOGV("Readout: Buffer %zu: Stream %d, %d x %d, format 0x%x, stride %d",
1361 i, b.streamId, b.width, b.height, b.format, b.stride);
1362 if (b.streamId > 0) {
1363 if (b.format == HAL_PIXEL_FORMAT_BLOB) {
1364 // Assumes only one BLOB buffer type per capture
1365 compressedBufferIndex = i;
1367 ALOGV("Readout: Sending image buffer %zu (%p) to output stream %d",
1368 i, (void*)*(b.buffer), b.streamId);
1369 GraphicBufferMapper::get().unlock(*(b.buffer));
1370 const Stream &s = mParent->getStreamInfo(b.streamId);
1371 res = s.ops->enqueue_buffer(s.ops, captureTime, b.buffer);
1373 ALOGE("Error enqueuing image buffer %p: %s (%d)", b.buffer,
1374 strerror(-res), res);
1375 mParent->signalError();
1381 if (compressedBufferIndex == -1) {
1384 ALOGV("Readout: Starting JPEG compression for buffer %d, stream %d",
1385 compressedBufferIndex,
1386 (*mBuffers)[compressedBufferIndex].streamId);
1387 mJpegTimestamp = captureTime;
1388 // Takes ownership of mBuffers
1389 mParent->mJpegCompressor->start(mBuffers, this);
1393 Mutex::Autolock l(mInputMutex);
1395 ALOGV("Readout: Done with request %d", frameNumber);
1399 void EmulatedFakeCamera2::ReadoutThread::onJpegDone(
1400 const StreamBuffer &jpegBuffer, bool success) {
1403 ALOGE("%s: Error queueing compressed image buffer %p",
1404 __FUNCTION__, jpegBuffer.buffer);
1405 mParent->signalError();
1409 // Write to JPEG output stream
1410 ALOGV("%s: Compression complete, pushing to stream %d", __FUNCTION__,
1411 jpegBuffer.streamId);
1413 GraphicBufferMapper::get().unlock(*(jpegBuffer.buffer));
1414 const Stream &s = mParent->getStreamInfo(jpegBuffer.streamId);
1415 res = s.ops->enqueue_buffer(s.ops, mJpegTimestamp, jpegBuffer.buffer);
1418 void EmulatedFakeCamera2::ReadoutThread::onJpegInputDone(
1419 const StreamBuffer &inputBuffer) {
1421 GraphicBufferMapper::get().unlock(*(inputBuffer.buffer));
1422 const ReprocessStream &s =
1423 mParent->getReprocessStreamInfo(-inputBuffer.streamId);
1424 res = s.ops->release_buffer(s.ops, inputBuffer.buffer);
1426 ALOGE("Error releasing reprocess buffer %p: %s (%d)",
1427 inputBuffer.buffer, strerror(-res), res);
1428 mParent->signalError();
1432 status_t EmulatedFakeCamera2::ReadoutThread::collectStatisticsMetadata(
1433 camera_metadata_t *frame) {
1434 // Completely fake face rectangles, don't correspond to real faces in scene
1435 ALOGV("Readout: Collecting statistics metadata");
1438 camera_metadata_entry_t entry;
1439 res = find_camera_metadata_entry(frame,
1440 ANDROID_STATISTICS_FACE_DETECT_MODE,
1443 ALOGE("%s: Unable to find face detect mode!", __FUNCTION__);
1447 if (entry.data.u8[0] == ANDROID_STATISTICS_FACE_DETECT_MODE_OFF) return OK;
1449 // The coordinate system for the face regions is the raw sensor pixel
1450 // coordinates. Here, we map from the scene coordinates (0-19 in both axis)
1451 // to raw pixels, for the scene defined in fake-pipeline2/Scene.cpp. We
1452 // approximately place two faces on top of the windows of the house. No
1453 // actual faces exist there, but might one day. Note that this doesn't
1454 // account for the offsets used to account for aspect ratio differences, so
1455 // the rectangles don't line up quite right.
1456 const size_t numFaces = 2;
1457 int32_t rects[numFaces * 4] = {
1458 static_cast<int32_t>(Sensor::kResolution[0] * 10 / 20),
1459 static_cast<int32_t>(Sensor::kResolution[1] * 15 / 20),
1460 static_cast<int32_t>(Sensor::kResolution[0] * 12 / 20),
1461 static_cast<int32_t>(Sensor::kResolution[1] * 17 / 20),
1463 static_cast<int32_t>(Sensor::kResolution[0] * 16 / 20),
1464 static_cast<int32_t>(Sensor::kResolution[1] * 15 / 20),
1465 static_cast<int32_t>(Sensor::kResolution[0] * 18 / 20),
1466 static_cast<int32_t>(Sensor::kResolution[1] * 17 / 20)
1468 // To simulate some kind of real detection going on, we jitter the rectangles on
1469 // each frame by a few pixels in each dimension.
1470 for (size_t i = 0; i < numFaces * 4; i++) {
1471 rects[i] += (int32_t)(((float)rand() / RAND_MAX) * 6 - 3);
1473 // The confidence scores (0-100) are similarly jittered.
1474 uint8_t scores[numFaces] = { 85, 95 };
1475 for (size_t i = 0; i < numFaces; i++) {
1476 scores[i] += (int32_t)(((float)rand() / RAND_MAX) * 10 - 5);
1479 res = add_camera_metadata_entry(frame, ANDROID_STATISTICS_FACE_RECTANGLES,
1480 rects, numFaces * 4);
1482 ALOGE("%s: Unable to add face rectangles!", __FUNCTION__);
1486 res = add_camera_metadata_entry(frame, ANDROID_STATISTICS_FACE_SCORES,
1489 ALOGE("%s: Unable to add face scores!", __FUNCTION__);
1493 if (entry.data.u8[0] == ANDROID_STATISTICS_FACE_DETECT_MODE_SIMPLE) return OK;
1495 // Advanced face detection options - add eye/mouth coordinates. The
1496 // coordinates in order are (leftEyeX, leftEyeY, rightEyeX, rightEyeY,
1497 // mouthX, mouthY). The mapping is the same as the face rectangles.
1498 int32_t features[numFaces * 6] = {
1499 static_cast<int32_t>(Sensor::kResolution[0] * 10.5 / 20),
1500 static_cast<int32_t>(Sensor::kResolution[1] * 16 / 20),
1501 static_cast<int32_t>(Sensor::kResolution[0] * 11.5 / 20),
1502 static_cast<int32_t>(Sensor::kResolution[1] * 16 / 20),
1503 static_cast<int32_t>(Sensor::kResolution[0] * 11 / 20),
1504 static_cast<int32_t>(Sensor::kResolution[1] * 16.5 / 20),
1506 static_cast<int32_t>(Sensor::kResolution[0] * 16.5 / 20),
1507 static_cast<int32_t>(Sensor::kResolution[1] * 16 / 20),
1508 static_cast<int32_t>(Sensor::kResolution[0] * 17.5 / 20),
1509 static_cast<int32_t>(Sensor::kResolution[1] * 16 / 20),
1510 static_cast<int32_t>(Sensor::kResolution[0] * 17 / 20),
1511 static_cast<int32_t>(Sensor::kResolution[1] * 16.5 / 20),
1513 // Jitter these a bit less than the rects
1514 for (size_t i = 0; i < numFaces * 6; i++) {
1515 features[i] += (int32_t)(((float)rand() / RAND_MAX) * 4 - 2);
1517 // These are unique IDs that are used to identify each face while it's
1518 // visible to the detector (if a face went away and came back, it'd get a
1520 int32_t ids[numFaces] = {
1524 res = add_camera_metadata_entry(frame, ANDROID_STATISTICS_FACE_LANDMARKS,
1525 features, numFaces * 6);
1527 ALOGE("%s: Unable to add face landmarks!", __FUNCTION__);
1531 res = add_camera_metadata_entry(frame, ANDROID_STATISTICS_FACE_IDS,
1534 ALOGE("%s: Unable to add face scores!", __FUNCTION__);
1541 EmulatedFakeCamera2::ControlThread::ControlThread(EmulatedFakeCamera2 *parent):
1547 EmulatedFakeCamera2::ControlThread::~ControlThread() {
1550 status_t EmulatedFakeCamera2::ControlThread::readyToRun() {
1551 Mutex::Autolock lock(mInputMutex);
1553 ALOGV("Starting up ControlThread");
1557 mStartPrecapture = false;
1559 mControlMode = ANDROID_CONTROL_MODE_AUTO;
1561 mEffectMode = ANDROID_CONTROL_EFFECT_MODE_OFF;
1562 mSceneMode = ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY;
1564 mAfMode = ANDROID_CONTROL_AF_MODE_AUTO;
1565 mAfModeChange = false;
1567 mAeMode = ANDROID_CONTROL_AE_MODE_ON;
1568 mAwbMode = ANDROID_CONTROL_AWB_MODE_AUTO;
1571 mPrecaptureTriggerId = 0;
1573 mAfState = ANDROID_CONTROL_AF_STATE_INACTIVE;
1574 mAeState = ANDROID_CONTROL_AE_STATE_INACTIVE;
1575 mAwbState = ANDROID_CONTROL_AWB_STATE_INACTIVE;
1577 mExposureTime = kNormalExposureTime;
1579 mInputSignal.signal();
1583 status_t EmulatedFakeCamera2::ControlThread::waitUntilRunning() {
1584 Mutex::Autolock lock(mInputMutex);
1586 ALOGV("Waiting for control thread to start");
1587 mInputSignal.wait(mInputMutex);
1592 // Override android.control.* fields with 3A values before sending request to sensor
1593 status_t EmulatedFakeCamera2::ControlThread::processRequest(camera_metadata_t *request) {
1594 Mutex::Autolock lock(mInputMutex);
1595 // TODO: Add handling for all android.control.* fields here
1596 camera_metadata_entry_t mode;
1599 #define READ_IF_OK(res, what, def) \
1600 (((res) == OK) ? (what) : (uint8_t)(def))
1602 res = find_camera_metadata_entry(request,
1603 ANDROID_CONTROL_MODE,
1605 mControlMode = READ_IF_OK(res, mode.data.u8[0], ANDROID_CONTROL_MODE_OFF);
1608 if (mControlMode == ANDROID_CONTROL_MODE_OFF) {
1609 mEffectMode = ANDROID_CONTROL_EFFECT_MODE_OFF;
1610 mSceneMode = ANDROID_CONTROL_SCENE_MODE_DISABLED;
1611 mAfMode = ANDROID_CONTROL_AF_MODE_OFF;
1612 mAeLock = ANDROID_CONTROL_AE_LOCK_ON;
1613 mAeMode = ANDROID_CONTROL_AE_MODE_OFF;
1614 mAfModeChange = true;
1617 mAeState = ANDROID_CONTROL_AE_STATE_INACTIVE;
1618 mAwbMode = ANDROID_CONTROL_AWB_MODE_OFF;
1622 res = find_camera_metadata_entry(request,
1623 ANDROID_CONTROL_EFFECT_MODE,
1625 mEffectMode = READ_IF_OK(res, mode.data.u8[0],
1626 ANDROID_CONTROL_EFFECT_MODE_OFF);
1628 res = find_camera_metadata_entry(request,
1629 ANDROID_CONTROL_SCENE_MODE,
1631 mSceneMode = READ_IF_OK(res, mode.data.u8[0],
1632 ANDROID_CONTROL_SCENE_MODE_DISABLED);
1634 res = find_camera_metadata_entry(request,
1635 ANDROID_CONTROL_AF_MODE,
1637 if (mAfMode != mode.data.u8[0]) {
1638 ALOGV("AF new mode: %d, old mode %d", mode.data.u8[0], mAfMode);
1639 mAfMode = mode.data.u8[0];
1640 mAfModeChange = true;
1645 res = find_camera_metadata_entry(request,
1646 ANDROID_CONTROL_AE_MODE,
1648 mAeMode = READ_IF_OK(res, mode.data.u8[0],
1649 ANDROID_CONTROL_AE_MODE_OFF);
1651 res = find_camera_metadata_entry(request,
1652 ANDROID_CONTROL_AE_LOCK,
1654 uint8_t aeLockVal = READ_IF_OK(res, mode.data.u8[0],
1655 ANDROID_CONTROL_AE_LOCK_ON);
1656 bool aeLock = (aeLockVal == ANDROID_CONTROL_AE_LOCK_ON);
1657 if (mAeLock && !aeLock) {
1658 mAeState = ANDROID_CONTROL_AE_STATE_INACTIVE;
1662 res = find_camera_metadata_entry(request,
1663 ANDROID_CONTROL_AWB_MODE,
1665 mAwbMode = READ_IF_OK(res, mode.data.u8[0],
1666 ANDROID_CONTROL_AWB_MODE_OFF);
1668 // TODO: Override more control fields
1670 if (mAeMode != ANDROID_CONTROL_AE_MODE_OFF) {
1671 camera_metadata_entry_t exposureTime;
1672 res = find_camera_metadata_entry(request,
1673 ANDROID_SENSOR_EXPOSURE_TIME,
1676 exposureTime.data.i64[0] = mExposureTime;
1685 status_t EmulatedFakeCamera2::ControlThread::triggerAction(uint32_t msgType,
1686 int32_t ext1, int32_t ext2) {
1687 ALOGV("%s: Triggering %d (%d, %d)", __FUNCTION__, msgType, ext1, ext2);
1688 Mutex::Autolock lock(mInputMutex);
1690 case CAMERA2_TRIGGER_AUTOFOCUS:
1691 mAfTriggerId = ext1;
1695 case CAMERA2_TRIGGER_CANCEL_AUTOFOCUS:
1696 mAfTriggerId = ext1;
1700 case CAMERA2_TRIGGER_PRECAPTURE_METERING:
1701 mPrecaptureTriggerId = ext1;
1702 mStartPrecapture = true;
1705 ALOGE("%s: Unknown action triggered: %d (arguments %d %d)",
1706 __FUNCTION__, msgType, ext1, ext2);
1712 const nsecs_t EmulatedFakeCamera2::ControlThread::kControlCycleDelay = 100 * MSEC;
1713 const nsecs_t EmulatedFakeCamera2::ControlThread::kMinAfDuration = 500 * MSEC;
1714 const nsecs_t EmulatedFakeCamera2::ControlThread::kMaxAfDuration = 900 * MSEC;
1715 const float EmulatedFakeCamera2::ControlThread::kAfSuccessRate = 0.9;
1716 // Once every 5 seconds
1717 const float EmulatedFakeCamera2::ControlThread::kContinuousAfStartRate =
1718 kControlCycleDelay / 5.0 * SEC;
1719 const nsecs_t EmulatedFakeCamera2::ControlThread::kMinAeDuration = 500 * MSEC;
1720 const nsecs_t EmulatedFakeCamera2::ControlThread::kMaxAeDuration = 2 * SEC;
1721 const nsecs_t EmulatedFakeCamera2::ControlThread::kMinPrecaptureAeDuration = 100 * MSEC;
1722 const nsecs_t EmulatedFakeCamera2::ControlThread::kMaxPrecaptureAeDuration = 400 * MSEC;
1723 // Once every 3 seconds
1724 const float EmulatedFakeCamera2::ControlThread::kAeScanStartRate =
1725 kControlCycleDelay / 3000000000.0;
1727 const nsecs_t EmulatedFakeCamera2::ControlThread::kNormalExposureTime = 10 * MSEC;
1728 const nsecs_t EmulatedFakeCamera2::ControlThread::kExposureJump = 2 * MSEC;
1729 const nsecs_t EmulatedFakeCamera2::ControlThread::kMinExposureTime = 1 * MSEC;
1731 bool EmulatedFakeCamera2::ControlThread::threadLoop() {
1732 bool afModeChange = false;
1733 bool afTriggered = false;
1734 bool afCancelled = false;
1737 int32_t afTriggerId;
1738 bool precaptureTriggered = false;
1742 int32_t precaptureTriggerId;
1743 nsecs_t nextSleep = kControlCycleDelay;
1746 Mutex::Autolock lock(mInputMutex);
1748 ALOGD("Starting AF trigger processing");
1751 } else if (mCancelAf) {
1752 ALOGD("Starting cancel AF trigger processing");
1758 afModeChange = mAfModeChange;
1759 mAfModeChange = false;
1761 afTriggerId = mAfTriggerId;
1763 if(mStartPrecapture) {
1764 ALOGD("Starting precapture trigger processing");
1765 precaptureTriggered = true;
1766 mStartPrecapture = false;
1771 precaptureTriggerId = mPrecaptureTriggerId;
1774 if (afCancelled || afModeChange) {
1775 ALOGV("Resetting AF state due to cancel/mode change");
1776 afState = ANDROID_CONTROL_AF_STATE_INACTIVE;
1777 updateAfState(afState, afTriggerId);
1778 mAfScanDuration = 0;
1779 mLockAfterPassiveScan = false;
1782 uint8_t oldAfState = afState;
1785 afState = processAfTrigger(afMode, afState);
1788 afState = maybeStartAfScan(afMode, afState);
1789 afState = updateAfScan(afMode, afState, &nextSleep);
1790 updateAfState(afState, afTriggerId);
1792 if (precaptureTriggered) {
1793 aeState = processPrecaptureTrigger(aeMode, aeState);
1796 aeState = maybeStartAeScan(aeMode, aeLock, aeState);
1797 aeState = updateAeScan(aeMode, aeLock, aeState, &nextSleep);
1798 updateAeState(aeState, precaptureTriggerId);
1803 t.tv_nsec = nextSleep;
1805 ret = nanosleep(&t, &t);
1808 if (mAfScanDuration > 0) {
1809 mAfScanDuration -= nextSleep;
1811 if (mAeScanDuration > 0) {
1812 mAeScanDuration -= nextSleep;
1818 int EmulatedFakeCamera2::ControlThread::processAfTrigger(uint8_t afMode,
1821 case ANDROID_CONTROL_AF_MODE_OFF:
1822 case ANDROID_CONTROL_AF_MODE_EDOF:
1825 case ANDROID_CONTROL_AF_MODE_MACRO:
1826 case ANDROID_CONTROL_AF_MODE_AUTO:
1828 case ANDROID_CONTROL_AF_STATE_INACTIVE:
1829 case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED:
1830 case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED:
1831 // Start new focusing cycle
1832 mAfScanDuration = ((double)rand() / RAND_MAX) *
1833 (kMaxAfDuration - kMinAfDuration) + kMinAfDuration;
1834 afState = ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN;
1835 ALOGV("%s: AF scan start, duration %" PRId64 " ms",
1836 __FUNCTION__, mAfScanDuration / 1000000);
1838 case ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN:
1839 // Ignore new request, already scanning
1842 ALOGE("Unexpected AF state in AUTO/MACRO AF mode: %d",
1846 case ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE:
1848 // Picture mode waits for passive scan to complete
1849 case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN:
1850 mLockAfterPassiveScan = true;
1852 case ANDROID_CONTROL_AF_STATE_INACTIVE:
1853 afState = ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED;
1855 case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED:
1856 afState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
1858 case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED:
1859 case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED:
1860 // Must cancel to get out of these states
1863 ALOGE("Unexpected AF state in CONTINUOUS_PICTURE AF mode: %d",
1867 case ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO:
1869 // Video mode does not wait for passive scan to complete
1870 case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN:
1871 case ANDROID_CONTROL_AF_STATE_INACTIVE:
1872 afState = ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED;
1874 case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED:
1875 afState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
1877 case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED:
1878 case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED:
1879 // Must cancel to get out of these states
1882 ALOGE("Unexpected AF state in CONTINUOUS_VIDEO AF mode: %d",
1892 int EmulatedFakeCamera2::ControlThread::maybeStartAfScan(uint8_t afMode,
1894 if ((afMode == ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO ||
1895 afMode == ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE) &&
1896 (afState == ANDROID_CONTROL_AF_STATE_INACTIVE ||
1897 afState == ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED)) {
1899 bool startScan = ((double)rand() / RAND_MAX) < kContinuousAfStartRate;
1901 // Start new passive focusing cycle
1902 mAfScanDuration = ((double)rand() / RAND_MAX) *
1903 (kMaxAfDuration - kMinAfDuration) + kMinAfDuration;
1904 afState = ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN;
1905 ALOGV("%s: AF passive scan start, duration %" PRId64 " ms",
1906 __FUNCTION__, mAfScanDuration / 1000000);
1912 int EmulatedFakeCamera2::ControlThread::updateAfScan(uint8_t afMode,
1913 uint8_t afState, nsecs_t *maxSleep) {
1914 if (! (afState == ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN ||
1915 afState == ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN ) ) {
1919 if (mAfScanDuration <= 0) {
1920 ALOGV("%s: AF scan done", __FUNCTION__);
1922 case ANDROID_CONTROL_AF_MODE_MACRO:
1923 case ANDROID_CONTROL_AF_MODE_AUTO: {
1924 bool success = ((double)rand() / RAND_MAX) < kAfSuccessRate;
1926 afState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
1928 afState = ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED;
1932 case ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE:
1933 if (mLockAfterPassiveScan) {
1934 afState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
1935 mLockAfterPassiveScan = false;
1937 afState = ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED;
1940 case ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO:
1941 afState = ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED;
1944 ALOGE("Unexpected AF mode in scan state");
1947 if (mAfScanDuration <= *maxSleep) {
1948 *maxSleep = mAfScanDuration;
1954 void EmulatedFakeCamera2::ControlThread::updateAfState(uint8_t newState,
1955 int32_t triggerId) {
1956 Mutex::Autolock lock(mInputMutex);
1957 if (mAfState != newState) {
1958 ALOGV("%s: Autofocus state now %d, id %d", __FUNCTION__,
1959 newState, triggerId);
1960 mAfState = newState;
1961 mParent->sendNotification(CAMERA2_MSG_AUTOFOCUS,
1962 newState, triggerId, 0);
1966 int EmulatedFakeCamera2::ControlThread::processPrecaptureTrigger(uint8_t aeMode,
1969 case ANDROID_CONTROL_AE_MODE_OFF:
1970 // Don't do anything for these
1972 case ANDROID_CONTROL_AE_MODE_ON:
1973 case ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH:
1974 case ANDROID_CONTROL_AE_MODE_ON_ALWAYS_FLASH:
1975 case ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE:
1976 // Trigger a precapture cycle
1977 aeState = ANDROID_CONTROL_AE_STATE_PRECAPTURE;
1978 mAeScanDuration = ((double)rand() / RAND_MAX) *
1979 (kMaxPrecaptureAeDuration - kMinPrecaptureAeDuration) +
1980 kMinPrecaptureAeDuration;
1981 ALOGD("%s: AE precapture scan start, duration %" PRId64 " ms",
1982 __FUNCTION__, mAeScanDuration / 1000000);
1988 int EmulatedFakeCamera2::ControlThread::maybeStartAeScan(uint8_t aeMode,
1991 if (aeLocked) return aeState;
1993 case ANDROID_CONTROL_AE_MODE_OFF:
1995 case ANDROID_CONTROL_AE_MODE_ON:
1996 case ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH:
1997 case ANDROID_CONTROL_AE_MODE_ON_ALWAYS_FLASH:
1998 case ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE: {
1999 if (aeState != ANDROID_CONTROL_AE_STATE_INACTIVE &&
2000 aeState != ANDROID_CONTROL_AE_STATE_CONVERGED) break;
2002 bool startScan = ((double)rand() / RAND_MAX) < kAeScanStartRate;
2004 mAeScanDuration = ((double)rand() / RAND_MAX) *
2005 (kMaxAeDuration - kMinAeDuration) + kMinAeDuration;
2006 aeState = ANDROID_CONTROL_AE_STATE_SEARCHING;
2007 ALOGV("%s: AE scan start, duration %" PRId64 " ms",
2008 __FUNCTION__, mAeScanDuration / 1000000);
2016 int EmulatedFakeCamera2::ControlThread::updateAeScan(uint8_t aeMode,
2017 bool aeLock, uint8_t aeState, nsecs_t *maxSleep) {
2018 if (aeLock && aeState != ANDROID_CONTROL_AE_STATE_PRECAPTURE) {
2019 mAeScanDuration = 0;
2020 aeState = ANDROID_CONTROL_AE_STATE_LOCKED;
2021 } else if ((aeState == ANDROID_CONTROL_AE_STATE_SEARCHING) ||
2022 (aeState == ANDROID_CONTROL_AE_STATE_PRECAPTURE ) ) {
2023 if (mAeScanDuration <= 0) {
2024 ALOGV("%s: AE scan done", __FUNCTION__);
2026 ANDROID_CONTROL_AE_STATE_LOCKED :ANDROID_CONTROL_AE_STATE_CONVERGED;
2028 Mutex::Autolock lock(mInputMutex);
2029 mExposureTime = kNormalExposureTime;
2031 if (mAeScanDuration <= *maxSleep) {
2032 *maxSleep = mAeScanDuration;
2035 int64_t exposureDelta =
2036 ((double)rand() / RAND_MAX) * 2 * kExposureJump -
2038 Mutex::Autolock lock(mInputMutex);
2039 mExposureTime = mExposureTime + exposureDelta;
2040 if (mExposureTime < kMinExposureTime) mExposureTime = kMinExposureTime;
2048 void EmulatedFakeCamera2::ControlThread::updateAeState(uint8_t newState,
2049 int32_t triggerId) {
2050 Mutex::Autolock lock(mInputMutex);
2051 if (mAeState != newState) {
2052 ALOGV("%s: Autoexposure state now %d, id %d", __FUNCTION__,
2053 newState, triggerId);
2054 mAeState = newState;
2055 mParent->sendNotification(CAMERA2_MSG_AUTOEXPOSURE,
2056 newState, triggerId, 0);
2060 /** Private methods */
2062 status_t EmulatedFakeCamera2::constructStaticInfo(
2063 camera_metadata_t **info,
2064 bool sizeRequest) const {
2066 size_t entryCount = 0;
2067 size_t dataCount = 0;
2070 #define ADD_OR_SIZE( tag, data, count ) \
2071 if ( ( ret = addOrSize(*info, sizeRequest, &entryCount, &dataCount, \
2072 tag, data, count) ) != OK ) return ret
2076 // 5 cm min focus distance for back camera, infinity (fixed focus) for front
2077 const float minFocusDistance = mFacingBack ? 1.0/0.05 : 0.0;
2078 ADD_OR_SIZE(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE,
2079 &minFocusDistance, 1);
2080 // 5 m hyperfocal distance for back camera, infinity (fixed focus) for front
2081 const float hyperFocalDistance = mFacingBack ? 1.0/5.0 : 0.0;
2082 ADD_OR_SIZE(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE,
2083 &minFocusDistance, 1);
2085 static const float focalLength = 3.30f; // mm
2086 ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS,
2088 static const float aperture = 2.8f;
2089 ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_APERTURES,
2091 static const float filterDensity = 0;
2092 ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES,
2094 static const uint8_t availableOpticalStabilization =
2095 ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF;
2096 ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
2097 &availableOpticalStabilization, 1);
2099 static const int32_t lensShadingMapSize[] = {1, 1};
2100 ADD_OR_SIZE(ANDROID_LENS_INFO_SHADING_MAP_SIZE, lensShadingMapSize,
2101 sizeof(lensShadingMapSize)/sizeof(int32_t));
2103 int32_t lensFacing = mFacingBack ?
2104 ANDROID_LENS_FACING_BACK : ANDROID_LENS_FACING_FRONT;
2105 ADD_OR_SIZE(ANDROID_LENS_FACING, &lensFacing, 1);
2109 ADD_OR_SIZE(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,
2110 Sensor::kExposureTimeRange, 2);
2112 ADD_OR_SIZE(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
2113 &Sensor::kFrameDurationRange[1], 1);
2115 ADD_OR_SIZE(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE,
2116 Sensor::kSensitivityRange,
2117 sizeof(Sensor::kSensitivityRange)
2120 ADD_OR_SIZE(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,
2121 &Sensor::kColorFilterArrangement, 1);
2123 static const float sensorPhysicalSize[2] = {3.20f, 2.40f}; // mm
2124 ADD_OR_SIZE(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
2125 sensorPhysicalSize, 2);
2127 ADD_OR_SIZE(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
2128 Sensor::kResolution, 2);
2130 ADD_OR_SIZE(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE,
2131 Sensor::kResolution, 2);
2133 ADD_OR_SIZE(ANDROID_SENSOR_INFO_WHITE_LEVEL,
2134 &Sensor::kMaxRawValue, 1);
2136 static const int32_t blackLevelPattern[4] = {
2137 static_cast<int32_t>(Sensor::kBlackLevel),
2138 static_cast<int32_t>(Sensor::kBlackLevel),
2139 static_cast<int32_t>(Sensor::kBlackLevel),
2140 static_cast<int32_t>(Sensor::kBlackLevel)
2142 ADD_OR_SIZE(ANDROID_SENSOR_BLACK_LEVEL_PATTERN,
2143 blackLevelPattern, sizeof(blackLevelPattern)/sizeof(int32_t));
2145 //TODO: sensor color calibration fields
2148 static const uint8_t flashAvailable = 0;
2149 ADD_OR_SIZE(ANDROID_FLASH_INFO_AVAILABLE, &flashAvailable, 1);
2151 static const int64_t flashChargeDuration = 0;
2152 ADD_OR_SIZE(ANDROID_FLASH_INFO_CHARGE_DURATION, &flashChargeDuration, 1);
2156 static const int32_t tonemapCurvePoints = 128;
2157 ADD_OR_SIZE(ANDROID_TONEMAP_MAX_CURVE_POINTS, &tonemapCurvePoints, 1);
2161 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_FORMATS,
2163 sizeof(kAvailableFormats)/sizeof(uint32_t));
2165 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_RAW_SIZES,
2167 sizeof(kAvailableRawSizes)/sizeof(uint32_t));
2169 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS,
2170 kAvailableRawMinDurations,
2171 sizeof(kAvailableRawMinDurations)/sizeof(uint64_t));
2174 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES,
2175 kAvailableProcessedSizesBack,
2176 sizeof(kAvailableProcessedSizesBack)/sizeof(uint32_t));
2178 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES,
2179 kAvailableProcessedSizesFront,
2180 sizeof(kAvailableProcessedSizesFront)/sizeof(uint32_t));
2183 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS,
2184 kAvailableProcessedMinDurations,
2185 sizeof(kAvailableProcessedMinDurations)/sizeof(uint64_t));
2188 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_SIZES,
2189 kAvailableJpegSizesBack,
2190 sizeof(kAvailableJpegSizesBack)/sizeof(uint32_t));
2192 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_SIZES,
2193 kAvailableJpegSizesFront,
2194 sizeof(kAvailableJpegSizesFront)/sizeof(uint32_t));
2197 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS,
2198 kAvailableJpegMinDurations,
2199 sizeof(kAvailableJpegMinDurations)/sizeof(uint64_t));
2201 static const float maxZoom = 10;
2202 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
2207 static const int32_t jpegThumbnailSizes[] = {
2212 ADD_OR_SIZE(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,
2213 jpegThumbnailSizes, sizeof(jpegThumbnailSizes)/sizeof(int32_t));
2215 static const int32_t jpegMaxSize = JpegCompressor::kMaxJpegSize;
2216 ADD_OR_SIZE(ANDROID_JPEG_MAX_SIZE, &jpegMaxSize, 1);
2220 static const uint8_t availableFaceDetectModes[] = {
2221 ANDROID_STATISTICS_FACE_DETECT_MODE_OFF,
2222 ANDROID_STATISTICS_FACE_DETECT_MODE_SIMPLE,
2223 ANDROID_STATISTICS_FACE_DETECT_MODE_FULL
2226 ADD_OR_SIZE(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES,
2227 availableFaceDetectModes,
2228 sizeof(availableFaceDetectModes));
2230 static const int32_t maxFaceCount = 8;
2231 ADD_OR_SIZE(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT,
2234 static const int32_t histogramSize = 64;
2235 ADD_OR_SIZE(ANDROID_STATISTICS_INFO_HISTOGRAM_BUCKET_COUNT,
2238 static const int32_t maxHistogramCount = 1000;
2239 ADD_OR_SIZE(ANDROID_STATISTICS_INFO_MAX_HISTOGRAM_COUNT,
2240 &maxHistogramCount, 1);
2242 static const int32_t sharpnessMapSize[2] = {64, 64};
2243 ADD_OR_SIZE(ANDROID_STATISTICS_INFO_SHARPNESS_MAP_SIZE,
2244 sharpnessMapSize, sizeof(sharpnessMapSize)/sizeof(int32_t));
2246 static const int32_t maxSharpnessMapValue = 1000;
2247 ADD_OR_SIZE(ANDROID_STATISTICS_INFO_MAX_SHARPNESS_MAP_VALUE,
2248 &maxSharpnessMapValue, 1);
2252 static const uint8_t availableSceneModes[] = {
2253 ANDROID_CONTROL_SCENE_MODE_DISABLED
2255 ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_SCENE_MODES,
2256 availableSceneModes, sizeof(availableSceneModes));
2258 static const uint8_t availableEffects[] = {
2259 ANDROID_CONTROL_EFFECT_MODE_OFF
2261 ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_EFFECTS,
2262 availableEffects, sizeof(availableEffects));
2264 static const int32_t max3aRegions[] = {/*AE*/ 0,/*AWB*/ 0,/*AF*/ 0};
2265 ADD_OR_SIZE(ANDROID_CONTROL_MAX_REGIONS,
2266 max3aRegions, sizeof(max3aRegions)/sizeof(max3aRegions[0]));
2268 static const uint8_t availableAeModes[] = {
2269 ANDROID_CONTROL_AE_MODE_OFF,
2270 ANDROID_CONTROL_AE_MODE_ON
2272 ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_MODES,
2273 availableAeModes, sizeof(availableAeModes));
2275 static const camera_metadata_rational exposureCompensationStep = {
2278 ADD_OR_SIZE(ANDROID_CONTROL_AE_COMPENSATION_STEP,
2279 &exposureCompensationStep, 1);
2281 int32_t exposureCompensationRange[] = {-9, 9};
2282 ADD_OR_SIZE(ANDROID_CONTROL_AE_COMPENSATION_RANGE,
2283 exposureCompensationRange,
2284 sizeof(exposureCompensationRange)/sizeof(int32_t));
2286 static const int32_t availableTargetFpsRanges[] = {
2289 ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
2290 availableTargetFpsRanges,
2291 sizeof(availableTargetFpsRanges)/sizeof(int32_t));
2293 static const uint8_t availableAntibandingModes[] = {
2294 ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF,
2295 ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO
2297 ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES,
2298 availableAntibandingModes, sizeof(availableAntibandingModes));
2300 static const uint8_t availableAwbModes[] = {
2301 ANDROID_CONTROL_AWB_MODE_OFF,
2302 ANDROID_CONTROL_AWB_MODE_AUTO,
2303 ANDROID_CONTROL_AWB_MODE_INCANDESCENT,
2304 ANDROID_CONTROL_AWB_MODE_FLUORESCENT,
2305 ANDROID_CONTROL_AWB_MODE_DAYLIGHT,
2306 ANDROID_CONTROL_AWB_MODE_SHADE
2308 ADD_OR_SIZE(ANDROID_CONTROL_AWB_AVAILABLE_MODES,
2309 availableAwbModes, sizeof(availableAwbModes));
2311 static const uint8_t availableAfModesBack[] = {
2312 ANDROID_CONTROL_AF_MODE_OFF,
2313 ANDROID_CONTROL_AF_MODE_AUTO,
2314 ANDROID_CONTROL_AF_MODE_MACRO,
2315 ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO,
2316 ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE
2319 static const uint8_t availableAfModesFront[] = {
2320 ANDROID_CONTROL_AF_MODE_OFF
2324 ADD_OR_SIZE(ANDROID_CONTROL_AF_AVAILABLE_MODES,
2325 availableAfModesBack, sizeof(availableAfModesBack));
2327 ADD_OR_SIZE(ANDROID_CONTROL_AF_AVAILABLE_MODES,
2328 availableAfModesFront, sizeof(availableAfModesFront));
2331 static const uint8_t availableVstabModes[] = {
2332 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF
2334 ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES,
2335 availableVstabModes, sizeof(availableVstabModes));
2338 /** Allocate metadata if sizing */
2340 ALOGV("Allocating %zu entries, %zu extra bytes for "
2341 "static camera info",
2342 entryCount, dataCount);
2343 *info = allocate_camera_metadata(entryCount, dataCount);
2344 if (*info == NULL) {
2345 ALOGE("Unable to allocate camera static info"
2346 "(%zu entries, %zu bytes extra data)",
2347 entryCount, dataCount);
2354 status_t EmulatedFakeCamera2::constructDefaultRequest(
2355 int request_template,
2356 camera_metadata_t **request,
2357 bool sizeRequest) const {
2359 size_t entryCount = 0;
2360 size_t dataCount = 0;
2363 #define ADD_OR_SIZE( tag, data, count ) \
2364 if ( ( ret = addOrSize(*request, sizeRequest, &entryCount, &dataCount, \
2365 tag, data, count) ) != OK ) return ret
2367 /** android.request */
2369 static const uint8_t requestType = ANDROID_REQUEST_TYPE_CAPTURE;
2370 ADD_OR_SIZE(ANDROID_REQUEST_TYPE, &requestType, 1);
2372 static const uint8_t metadataMode = ANDROID_REQUEST_METADATA_MODE_FULL;
2373 ADD_OR_SIZE(ANDROID_REQUEST_METADATA_MODE, &metadataMode, 1);
2375 static const int32_t id = 0;
2376 ADD_OR_SIZE(ANDROID_REQUEST_ID, &id, 1);
2378 static const int32_t frameCount = 0;
2379 ADD_OR_SIZE(ANDROID_REQUEST_FRAME_COUNT, &frameCount, 1);
2381 // OUTPUT_STREAMS set by user
2383 dataCount += 5; // TODO: Should be maximum stream number
2387 static const float focusDistance = 0;
2388 ADD_OR_SIZE(ANDROID_LENS_FOCUS_DISTANCE, &focusDistance, 1);
2390 static const float aperture = 2.8f;
2391 ADD_OR_SIZE(ANDROID_LENS_APERTURE, &aperture, 1);
2393 static const float focalLength = 5.0f;
2394 ADD_OR_SIZE(ANDROID_LENS_FOCAL_LENGTH, &focalLength, 1);
2396 static const float filterDensity = 0;
2397 ADD_OR_SIZE(ANDROID_LENS_FILTER_DENSITY, &filterDensity, 1);
2399 static const uint8_t opticalStabilizationMode =
2400 ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF;
2401 ADD_OR_SIZE(ANDROID_LENS_OPTICAL_STABILIZATION_MODE,
2402 &opticalStabilizationMode, 1);
2404 // FOCUS_RANGE set only in frame
2406 /** android.sensor */
2408 static const int64_t exposureTime = 10 * MSEC;
2409 ADD_OR_SIZE(ANDROID_SENSOR_EXPOSURE_TIME, &exposureTime, 1);
2411 static const int64_t frameDuration = 33333333L; // 1/30 s
2412 ADD_OR_SIZE(ANDROID_SENSOR_FRAME_DURATION, &frameDuration, 1);
2414 static const int32_t sensitivity = 100;
2415 ADD_OR_SIZE(ANDROID_SENSOR_SENSITIVITY, &sensitivity, 1);
2417 // TIMESTAMP set only in frame
2419 /** android.flash */
2421 static const uint8_t flashMode = ANDROID_FLASH_MODE_OFF;
2422 ADD_OR_SIZE(ANDROID_FLASH_MODE, &flashMode, 1);
2424 static const uint8_t flashPower = 10;
2425 ADD_OR_SIZE(ANDROID_FLASH_FIRING_POWER, &flashPower, 1);
2427 static const int64_t firingTime = 0;
2428 ADD_OR_SIZE(ANDROID_FLASH_FIRING_TIME, &firingTime, 1);
2430 /** Processing block modes */
2431 uint8_t hotPixelMode = 0;
2432 uint8_t demosaicMode = 0;
2433 uint8_t noiseMode = 0;
2434 uint8_t shadingMode = 0;
2435 uint8_t colorMode = 0;
2436 uint8_t tonemapMode = 0;
2437 uint8_t edgeMode = 0;
2438 switch (request_template) {
2439 case CAMERA2_TEMPLATE_STILL_CAPTURE:
2441 case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT:
2443 case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG:
2444 hotPixelMode = ANDROID_HOT_PIXEL_MODE_HIGH_QUALITY;
2445 demosaicMode = ANDROID_DEMOSAIC_MODE_HIGH_QUALITY;
2446 noiseMode = ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY;
2447 shadingMode = ANDROID_SHADING_MODE_HIGH_QUALITY;
2448 colorMode = ANDROID_COLOR_CORRECTION_MODE_HIGH_QUALITY;
2449 tonemapMode = ANDROID_TONEMAP_MODE_HIGH_QUALITY;
2450 edgeMode = ANDROID_EDGE_MODE_HIGH_QUALITY;
2452 case CAMERA2_TEMPLATE_PREVIEW:
2454 case CAMERA2_TEMPLATE_VIDEO_RECORD:
2457 hotPixelMode = ANDROID_HOT_PIXEL_MODE_FAST;
2458 demosaicMode = ANDROID_DEMOSAIC_MODE_FAST;
2459 noiseMode = ANDROID_NOISE_REDUCTION_MODE_FAST;
2460 shadingMode = ANDROID_SHADING_MODE_FAST;
2461 colorMode = ANDROID_COLOR_CORRECTION_MODE_FAST;
2462 tonemapMode = ANDROID_TONEMAP_MODE_FAST;
2463 edgeMode = ANDROID_EDGE_MODE_FAST;
2466 ADD_OR_SIZE(ANDROID_HOT_PIXEL_MODE, &hotPixelMode, 1);
2467 ADD_OR_SIZE(ANDROID_DEMOSAIC_MODE, &demosaicMode, 1);
2468 ADD_OR_SIZE(ANDROID_NOISE_REDUCTION_MODE, &noiseMode, 1);
2469 ADD_OR_SIZE(ANDROID_SHADING_MODE, &shadingMode, 1);
2470 ADD_OR_SIZE(ANDROID_COLOR_CORRECTION_MODE, &colorMode, 1);
2471 ADD_OR_SIZE(ANDROID_TONEMAP_MODE, &tonemapMode, 1);
2472 ADD_OR_SIZE(ANDROID_EDGE_MODE, &edgeMode, 1);
2474 /** android.noise */
2475 static const uint8_t noiseStrength = 5;
2476 ADD_OR_SIZE(ANDROID_NOISE_REDUCTION_STRENGTH, &noiseStrength, 1);
2478 /** android.color */
2479 static const float colorTransform[9] = {
2484 ADD_OR_SIZE(ANDROID_COLOR_CORRECTION_TRANSFORM, colorTransform, 9);
2486 /** android.tonemap */
2487 static const float tonemapCurve[4] = {
2491 ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_RED, tonemapCurve, 4);
2492 ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_GREEN, tonemapCurve, 4);
2493 ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_BLUE, tonemapCurve, 4);
2496 static const uint8_t edgeStrength = 5;
2497 ADD_OR_SIZE(ANDROID_EDGE_STRENGTH, &edgeStrength, 1);
2499 /** android.scaler */
2500 static const int32_t cropRegion[3] = {
2501 0, 0, static_cast<int32_t>(Sensor::kResolution[0])
2503 ADD_OR_SIZE(ANDROID_SCALER_CROP_REGION, cropRegion, 3);
2506 static const int32_t jpegQuality = 80;
2507 ADD_OR_SIZE(ANDROID_JPEG_QUALITY, &jpegQuality, 1);
2509 static const int32_t thumbnailSize[2] = {
2512 ADD_OR_SIZE(ANDROID_JPEG_THUMBNAIL_SIZE, thumbnailSize, 2);
2514 static const int32_t thumbnailQuality = 80;
2515 ADD_OR_SIZE(ANDROID_JPEG_THUMBNAIL_QUALITY, &thumbnailQuality, 1);
2517 static const double gpsCoordinates[2] = {
2520 ADD_OR_SIZE(ANDROID_JPEG_GPS_COORDINATES, gpsCoordinates, 2);
2522 static const uint8_t gpsProcessingMethod[32] = "None";
2523 ADD_OR_SIZE(ANDROID_JPEG_GPS_PROCESSING_METHOD, gpsProcessingMethod, 32);
2525 static const int64_t gpsTimestamp = 0;
2526 ADD_OR_SIZE(ANDROID_JPEG_GPS_TIMESTAMP, &gpsTimestamp, 1);
2528 static const int32_t jpegOrientation = 0;
2529 ADD_OR_SIZE(ANDROID_JPEG_ORIENTATION, &jpegOrientation, 1);
2531 /** android.stats */
2533 static const uint8_t faceDetectMode =
2534 ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
2535 ADD_OR_SIZE(ANDROID_STATISTICS_FACE_DETECT_MODE, &faceDetectMode, 1);
2537 static const uint8_t histogramMode = ANDROID_STATISTICS_HISTOGRAM_MODE_OFF;
2538 ADD_OR_SIZE(ANDROID_STATISTICS_HISTOGRAM_MODE, &histogramMode, 1);
2540 static const uint8_t sharpnessMapMode =
2541 ANDROID_STATISTICS_SHARPNESS_MAP_MODE_OFF;
2542 ADD_OR_SIZE(ANDROID_STATISTICS_SHARPNESS_MAP_MODE, &sharpnessMapMode, 1);
2544 // faceRectangles, faceScores, faceLandmarks, faceIds, histogram,
2545 // sharpnessMap only in frames
2547 /** android.control */
2549 uint8_t controlIntent = 0;
2550 switch (request_template) {
2551 case CAMERA2_TEMPLATE_PREVIEW:
2552 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
2554 case CAMERA2_TEMPLATE_STILL_CAPTURE:
2555 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
2557 case CAMERA2_TEMPLATE_VIDEO_RECORD:
2558 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
2560 case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT:
2561 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT;
2563 case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG:
2564 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG;
2567 controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM;
2570 ADD_OR_SIZE(ANDROID_CONTROL_CAPTURE_INTENT, &controlIntent, 1);
2572 static const uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO;
2573 ADD_OR_SIZE(ANDROID_CONTROL_MODE, &controlMode, 1);
2575 static const uint8_t effectMode = ANDROID_CONTROL_EFFECT_MODE_OFF;
2576 ADD_OR_SIZE(ANDROID_CONTROL_EFFECT_MODE, &effectMode, 1);
2578 static const uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY;
2579 ADD_OR_SIZE(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1);
2581 static const uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH;
2582 ADD_OR_SIZE(ANDROID_CONTROL_AE_MODE, &aeMode, 1);
2584 static const uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF;
2585 ADD_OR_SIZE(ANDROID_CONTROL_AE_LOCK, &aeLock, 1);
2587 static const int32_t controlRegions[5] = {
2589 static_cast<int32_t>(Sensor::kResolution[0]),
2590 static_cast<int32_t>(Sensor::kResolution[1]),
2593 ADD_OR_SIZE(ANDROID_CONTROL_AE_REGIONS, controlRegions, 5);
2595 static const int32_t aeExpCompensation = 0;
2596 ADD_OR_SIZE(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, &aeExpCompensation, 1);
2598 static const int32_t aeTargetFpsRange[2] = {
2601 ADD_OR_SIZE(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, aeTargetFpsRange, 2);
2603 static const uint8_t aeAntibandingMode =
2604 ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO;
2605 ADD_OR_SIZE(ANDROID_CONTROL_AE_ANTIBANDING_MODE, &aeAntibandingMode, 1);
2607 static const uint8_t awbMode =
2608 ANDROID_CONTROL_AWB_MODE_AUTO;
2609 ADD_OR_SIZE(ANDROID_CONTROL_AWB_MODE, &awbMode, 1);
2611 static const uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF;
2612 ADD_OR_SIZE(ANDROID_CONTROL_AWB_LOCK, &awbLock, 1);
2614 ADD_OR_SIZE(ANDROID_CONTROL_AWB_REGIONS, controlRegions, 5);
2617 switch (request_template) {
2618 case CAMERA2_TEMPLATE_PREVIEW:
2619 afMode = ANDROID_CONTROL_AF_MODE_AUTO;
2621 case CAMERA2_TEMPLATE_STILL_CAPTURE:
2622 afMode = ANDROID_CONTROL_AF_MODE_AUTO;
2624 case CAMERA2_TEMPLATE_VIDEO_RECORD:
2625 afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
2627 case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT:
2628 afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
2630 case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG:
2631 afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
2634 afMode = ANDROID_CONTROL_AF_MODE_AUTO;
2637 ADD_OR_SIZE(ANDROID_CONTROL_AF_MODE, &afMode, 1);
2639 ADD_OR_SIZE(ANDROID_CONTROL_AF_REGIONS, controlRegions, 5);
2641 static const uint8_t vstabMode =
2642 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF;
2643 ADD_OR_SIZE(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, &vstabMode, 1);
2645 // aeState, awbState, afState only in frame
2647 /** Allocate metadata if sizing */
2649 ALOGV("Allocating %zu entries, %zu extra bytes for "
2650 "request template type %d",
2651 entryCount, dataCount, request_template);
2652 *request = allocate_camera_metadata(entryCount, dataCount);
2653 if (*request == NULL) {
2654 ALOGE("Unable to allocate new request template type %d "
2655 "(%zu entries, %zu bytes extra data)", request_template,
2656 entryCount, dataCount);
2664 status_t EmulatedFakeCamera2::addOrSize(camera_metadata_t *request,
2669 const void *entryData,
2670 size_t entryDataCount) {
2673 return add_camera_metadata_entry(request, tag, entryData,
2676 int type = get_camera_metadata_tag_type(tag);
2677 if (type < 0 ) return BAD_VALUE;
2679 (*dataCount) += calculate_camera_metadata_entry_data_size(type,
2685 bool EmulatedFakeCamera2::isStreamInUse(uint32_t id) {
2686 // Assumes mMutex is locked; otherwise new requests could enter
2687 // configureThread while readoutThread is being checked
2689 // Order of isStreamInUse calls matters
2690 if (mConfigureThread->isStreamInUse(id) ||
2691 mReadoutThread->isStreamInUse(id) ||
2692 mJpegCompressor->isStreamInUse(id) ) {
2693 ALOGE("%s: Stream %d is in use in active requests!",
2700 bool EmulatedFakeCamera2::isReprocessStreamInUse(uint32_t id) {
2705 const Stream& EmulatedFakeCamera2::getStreamInfo(uint32_t streamId) {
2706 Mutex::Autolock lock(mMutex);
2708 return mStreams.valueFor(streamId);
2711 const ReprocessStream& EmulatedFakeCamera2::getReprocessStreamInfo(uint32_t streamId) {
2712 Mutex::Autolock lock(mMutex);
2714 return mReprocessStreams.valueFor(streamId);
2717 }; /* namespace android */