| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2012 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 |  | 
| Zhijun He | cc27e11 | 2013-10-03 16:12:43 -0700 | [diff] [blame] | 17 | #define LOG_TAG "Camera2Client" | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 20 |  | 
| Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 21 | #include <inttypes.h> | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 22 | #include <utils/Log.h> | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 23 | #include <utils/Trace.h> | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | #include <cutils/properties.h> | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 26 | #include <gui/Surface.h> | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 27 | #include <android/hardware/camera2/ICameraDeviceCallbacks.h> | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 28 |  | 
| Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 29 | #include "api1/Camera2Client.h" | 
|  | 30 |  | 
|  | 31 | #include "api1/client2/StreamingProcessor.h" | 
|  | 32 | #include "api1/client2/JpegProcessor.h" | 
|  | 33 | #include "api1/client2/CaptureSequencer.h" | 
|  | 34 | #include "api1/client2/CallbackProcessor.h" | 
|  | 35 | #include "api1/client2/ZslProcessor.h" | 
| Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 36 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 37 | #define ALOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); | 
|  | 38 | #define ALOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); | 
|  | 39 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 40 | namespace android { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 41 | using namespace camera2; | 
|  | 42 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 43 | static int getCallingPid() { | 
|  | 44 | return IPCThreadState::self()->getCallingPid(); | 
|  | 45 | } | 
|  | 46 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 47 | // Interface used by CameraService | 
|  | 48 |  | 
|  | 49 | Camera2Client::Camera2Client(const sp<CameraService>& cameraService, | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 50 | const sp<hardware::ICameraClient>& cameraClient, | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 51 | const String16& clientPackageName, | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 52 | int cameraId, | 
|  | 53 | int cameraFacing, | 
| Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 54 | int clientPid, | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 55 | uid_t clientUid, | 
| Igor Murashkin | a858ea0 | 2014-08-19 14:53:08 -0700 | [diff] [blame] | 56 | int servicePid, | 
|  | 57 | bool legacyMode): | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 58 | Camera2ClientBase(cameraService, cameraClient, clientPackageName, | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 59 | cameraId, cameraFacing, clientPid, clientUid, servicePid), | 
| Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 60 | mParameters(cameraId, cameraFacing) | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 61 | { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 62 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 63 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 64 | SharedParameters::Lock l(mParameters); | 
|  | 65 | l.mParameters.state = Parameters::DISCONNECTED; | 
| Igor Murashkin | a858ea0 | 2014-08-19 14:53:08 -0700 | [diff] [blame] | 66 |  | 
|  | 67 | mLegacyMode = legacyMode; | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
| Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 70 | status_t Camera2Client::initialize(CameraModule *module) | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 71 | { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 72 | ATRACE_CALL(); | 
| Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 73 | ALOGV("%s: Initializing client for camera %d", __FUNCTION__, mCameraId); | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 74 | status_t res; | 
|  | 75 |  | 
| Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 76 | res = Camera2ClientBase::initialize(module); | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 77 | if (res != OK) { | 
|  | 78 | return res; | 
|  | 79 | } | 
|  | 80 |  | 
| Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 81 | { | 
|  | 82 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 83 |  | 
| Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 84 | res = l.mParameters.initialize(&(mDevice->info()), mDeviceVersion); | 
| Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 85 | if (res != OK) { | 
|  | 86 | ALOGE("%s: Camera %d: unable to build defaults: %s (%d)", | 
|  | 87 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 88 | return NO_INIT; | 
|  | 89 | } | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 90 | } | 
| Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 91 |  | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 92 | String8 threadName; | 
| Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 93 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 94 | mStreamingProcessor = new StreamingProcessor(this); | 
| Eino-Ville Talvala | 254446a | 2013-06-04 16:34:35 -0700 | [diff] [blame] | 95 | threadName = String8::format("C2-%d-StreamProc", | 
|  | 96 | mCameraId); | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 97 |  | 
| Igor Murashkin | ce124da | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 98 | mFrameProcessor = new FrameProcessor(mDevice, this); | 
| Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 99 | threadName = String8::format("C2-%d-FrameProc", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 100 | mCameraId); | 
|  | 101 | mFrameProcessor->run(threadName.string()); | 
|  | 102 |  | 
|  | 103 | mCaptureSequencer = new CaptureSequencer(this); | 
| Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 104 | threadName = String8::format("C2-%d-CaptureSeq", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 105 | mCameraId); | 
|  | 106 | mCaptureSequencer->run(threadName.string()); | 
|  | 107 |  | 
|  | 108 | mJpegProcessor = new JpegProcessor(this, mCaptureSequencer); | 
| Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 109 | threadName = String8::format("C2-%d-JpegProc", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 110 | mCameraId); | 
|  | 111 | mJpegProcessor->run(threadName.string()); | 
|  | 112 |  | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 113 | mZslProcessor = new ZslProcessor(this, mCaptureSequencer); | 
|  | 114 |  | 
| Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 115 | threadName = String8::format("C2-%d-ZslProc", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 116 | mCameraId); | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 117 | mZslProcessor->run(threadName.string()); | 
| Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 118 |  | 
| Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 119 | mCallbackProcessor = new CallbackProcessor(this); | 
| Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 120 | threadName = String8::format("C2-%d-CallbkProc", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 121 | mCameraId); | 
|  | 122 | mCallbackProcessor->run(threadName.string()); | 
| Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 123 |  | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 124 | if (gLogLevel >= 1) { | 
| Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 125 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 126 | ALOGD("%s: Default parameters converted from camera %d:", __FUNCTION__, | 
|  | 127 | mCameraId); | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 128 | ALOGD("%s", l.mParameters.paramsFlattened.string()); | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 129 | } | 
|  | 130 |  | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 131 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
|  | 134 | Camera2Client::~Camera2Client() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 135 | ATRACE_CALL(); | 
| Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 136 | ALOGV("~Camera2Client"); | 
| Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 137 |  | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 138 | mDestructionStarted = true; | 
|  | 139 |  | 
| Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 140 | disconnect(); | 
| Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 141 |  | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 142 | ALOGI("Camera %d: Closed", mCameraId); | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 143 | } | 
|  | 144 |  | 
|  | 145 | status_t Camera2Client::dump(int fd, const Vector<String16>& args) { | 
| Eino-Ville Talvala | c400396 | 2016-01-13 10:07:04 -0800 | [diff] [blame] | 146 | return BasicClient::dump(fd, args); | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | status_t Camera2Client::dumpClient(int fd, const Vector<String16>& args) { | 
| Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 150 | String8 result; | 
| Ruben Brunk | cc77671 | 2015-02-17 20:18:47 -0800 | [diff] [blame] | 151 | result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n", mCameraId, | 
| Eino-Ville Talvala | e992e75 | 2014-11-07 16:17:48 -0800 | [diff] [blame] | 152 | (getRemoteCallback() != NULL ? | 
| Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 153 | (IInterface::asBinder(getRemoteCallback()).get()) : NULL), | 
| Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 154 | mClientPid); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 155 | result.append("  State: "); | 
|  | 156 | #define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break; | 
|  | 157 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 158 | const Parameters& p = mParameters.unsafeAccess(); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 159 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 160 | result.append(Parameters::getStateName(p.state)); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 161 |  | 
| Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 162 | result.append("\n  Current parameters:\n"); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 163 | result.appendFormat("    Preview size: %d x %d\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 164 | p.previewWidth, p.previewHeight); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 165 | result.appendFormat("    Preview FPS range: %d - %d\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 166 | p.previewFpsRange[0], p.previewFpsRange[1]); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 167 | result.appendFormat("    Preview HAL pixel format: 0x%x\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 168 | p.previewFormat); | 
| Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 169 | result.appendFormat("    Preview transform: %x\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 170 | p.previewTransform); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 171 | result.appendFormat("    Picture size: %d x %d\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 172 | p.pictureWidth, p.pictureHeight); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 173 | result.appendFormat("    Jpeg thumbnail size: %d x %d\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 174 | p.jpegThumbSize[0], p.jpegThumbSize[1]); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 175 | result.appendFormat("    Jpeg quality: %d, thumbnail quality: %d\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 176 | p.jpegQuality, p.jpegThumbQuality); | 
|  | 177 | result.appendFormat("    Jpeg rotation: %d\n", p.jpegRotation); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 178 | result.appendFormat("    GPS tags %s\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 179 | p.gpsEnabled ? "enabled" : "disabled"); | 
|  | 180 | if (p.gpsEnabled) { | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 181 | result.appendFormat("    GPS lat x long x alt: %f x %f x %f\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 182 | p.gpsCoordinates[0], p.gpsCoordinates[1], | 
|  | 183 | p.gpsCoordinates[2]); | 
| Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 184 | result.appendFormat("    GPS timestamp: %" PRId64 "\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 185 | p.gpsTimestamp); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 186 | result.appendFormat("    GPS processing method: %s\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 187 | p.gpsProcessingMethod.string()); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
|  | 190 | result.append("    White balance mode: "); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 191 | switch (p.wbMode) { | 
| Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 192 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_AUTO) | 
|  | 193 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_INCANDESCENT) | 
|  | 194 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_FLUORESCENT) | 
|  | 195 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_WARM_FLUORESCENT) | 
|  | 196 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_DAYLIGHT) | 
|  | 197 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT) | 
|  | 198 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_TWILIGHT) | 
|  | 199 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_SHADE) | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 200 | default: result.append("UNKNOWN\n"); | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | result.append("    Effect mode: "); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 204 | switch (p.effectMode) { | 
| Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 205 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_OFF) | 
|  | 206 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_MONO) | 
|  | 207 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_NEGATIVE) | 
|  | 208 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_SOLARIZE) | 
|  | 209 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_SEPIA) | 
|  | 210 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_POSTERIZE) | 
|  | 211 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_WHITEBOARD) | 
|  | 212 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_BLACKBOARD) | 
|  | 213 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_AQUA) | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 214 | default: result.append("UNKNOWN\n"); | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | result.append("    Antibanding mode: "); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 218 | switch (p.antibandingMode) { | 
| Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 219 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO) | 
|  | 220 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF) | 
|  | 221 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ) | 
|  | 222 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ) | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 223 | default: result.append("UNKNOWN\n"); | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | result.append("    Scene mode: "); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 227 | switch (p.sceneMode) { | 
| Ruben Brunk | c69b91c | 2014-01-17 17:12:10 -0800 | [diff] [blame] | 228 | case ANDROID_CONTROL_SCENE_MODE_DISABLED: | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 229 | result.append("AUTO\n"); break; | 
|  | 230 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_ACTION) | 
|  | 231 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PORTRAIT) | 
|  | 232 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_LANDSCAPE) | 
|  | 233 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT) | 
|  | 234 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT) | 
|  | 235 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_THEATRE) | 
|  | 236 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BEACH) | 
|  | 237 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SNOW) | 
|  | 238 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SUNSET) | 
|  | 239 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO) | 
|  | 240 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_FIREWORKS) | 
|  | 241 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SPORTS) | 
|  | 242 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PARTY) | 
|  | 243 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT) | 
|  | 244 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BARCODE) | 
|  | 245 | default: result.append("UNKNOWN\n"); | 
|  | 246 | } | 
|  | 247 |  | 
|  | 248 | result.append("    Flash mode: "); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 249 | switch (p.flashMode) { | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 250 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_OFF) | 
|  | 251 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_AUTO) | 
|  | 252 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_ON) | 
|  | 253 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_TORCH) | 
|  | 254 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_RED_EYE) | 
|  | 255 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_INVALID) | 
|  | 256 | default: result.append("UNKNOWN\n"); | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | result.append("    Focus mode: "); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 260 | switch (p.focusMode) { | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 261 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_AUTO) | 
|  | 262 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_MACRO) | 
|  | 263 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_VIDEO) | 
|  | 264 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_PICTURE) | 
|  | 265 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_EDOF) | 
|  | 266 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INFINITY) | 
|  | 267 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_FIXED) | 
|  | 268 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INVALID) | 
|  | 269 | default: result.append("UNKNOWN\n"); | 
|  | 270 | } | 
|  | 271 |  | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 272 | result.append("   Focus state: "); | 
|  | 273 | switch (p.focusState) { | 
|  | 274 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_INACTIVE) | 
|  | 275 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN) | 
|  | 276 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED) | 
| Eino-Ville Talvala | 4ad28ea | 2013-09-20 17:21:18 -0700 | [diff] [blame] | 277 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_UNFOCUSED) | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 278 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN) | 
|  | 279 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED) | 
|  | 280 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) | 
|  | 281 | default: result.append("UNKNOWN\n"); | 
|  | 282 | } | 
|  | 283 |  | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 284 | result.append("    Focusing areas:\n"); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 285 | for (size_t i = 0; i < p.focusingAreas.size(); i++) { | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 286 | result.appendFormat("      [ (%d, %d, %d, %d), weight %d ]\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 287 | p.focusingAreas[i].left, | 
|  | 288 | p.focusingAreas[i].top, | 
|  | 289 | p.focusingAreas[i].right, | 
|  | 290 | p.focusingAreas[i].bottom, | 
|  | 291 | p.focusingAreas[i].weight); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 292 | } | 
|  | 293 |  | 
|  | 294 | result.appendFormat("    Exposure compensation index: %d\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 295 | p.exposureCompensation); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 296 |  | 
|  | 297 | result.appendFormat("    AE lock %s, AWB lock %s\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 298 | p.autoExposureLock ? "enabled" : "disabled", | 
|  | 299 | p.autoWhiteBalanceLock ? "enabled" : "disabled" ); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 300 |  | 
|  | 301 | result.appendFormat("    Metering areas:\n"); | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 302 | for (size_t i = 0; i < p.meteringAreas.size(); i++) { | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 303 | result.appendFormat("      [ (%d, %d, %d, %d), weight %d ]\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 304 | p.meteringAreas[i].left, | 
|  | 305 | p.meteringAreas[i].top, | 
|  | 306 | p.meteringAreas[i].right, | 
|  | 307 | p.meteringAreas[i].bottom, | 
|  | 308 | p.meteringAreas[i].weight); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 309 | } | 
|  | 310 |  | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 311 | result.appendFormat("    Zoom index: %d\n", p.zoom); | 
|  | 312 | result.appendFormat("    Video size: %d x %d\n", p.videoWidth, | 
|  | 313 | p.videoHeight); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 314 |  | 
| Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 315 | result.appendFormat("    Recording hint is %s\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 316 | p.recordingHint ? "set" : "not set"); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 317 |  | 
| Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 318 | result.appendFormat("    Video stabilization is %s\n", | 
| Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 319 | p.videoStabilization ? "enabled" : "disabled"); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 320 |  | 
| Eino-Ville Talvala | 0181fde | 2013-09-20 10:12:32 -0700 | [diff] [blame] | 321 | result.appendFormat("    Selected still capture FPS range: %d - %d\n", | 
|  | 322 | p.fastInfo.bestStillCaptureFpsRange[0], | 
|  | 323 | p.fastInfo.bestStillCaptureFpsRange[1]); | 
|  | 324 |  | 
| Eino-Ville Talvala | c451d0f | 2016-06-30 17:17:35 -0700 | [diff] [blame] | 325 | result.appendFormat("    Use zero shutter lag: %s\n", | 
|  | 326 | p.useZeroShutterLag() ? "yes" : "no"); | 
|  | 327 |  | 
| Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 328 | result.append("  Current streams:\n"); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 329 | result.appendFormat("    Preview stream ID: %d\n", | 
|  | 330 | getPreviewStreamId()); | 
| Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 331 | result.appendFormat("    Capture stream ID: %d\n", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 332 | getCaptureStreamId()); | 
|  | 333 | result.appendFormat("    Recording stream ID: %d\n", | 
|  | 334 | getRecordingStreamId()); | 
| Eino-Ville Talvala | e382ee2 | 2012-10-02 18:14:49 -0700 | [diff] [blame] | 335 |  | 
|  | 336 | result.append("  Quirks for this camera:\n"); | 
|  | 337 | bool haveQuirk = false; | 
|  | 338 | if (p.quirks.triggerAfWithAuto) { | 
|  | 339 | result.appendFormat("    triggerAfWithAuto\n"); | 
|  | 340 | haveQuirk = true; | 
|  | 341 | } | 
|  | 342 | if (p.quirks.useZslFormat) { | 
|  | 343 | result.appendFormat("    useZslFormat\n"); | 
|  | 344 | haveQuirk = true; | 
|  | 345 | } | 
| Igor Murashkin | 7373cbe | 2012-09-28 15:30:03 -0700 | [diff] [blame] | 346 | if (p.quirks.meteringCropRegion) { | 
|  | 347 | result.appendFormat("    meteringCropRegion\n"); | 
|  | 348 | haveQuirk = true; | 
|  | 349 | } | 
| Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 350 | if (p.quirks.partialResults) { | 
|  | 351 | result.appendFormat("    usePartialResult\n"); | 
|  | 352 | haveQuirk = true; | 
|  | 353 | } | 
| Eino-Ville Talvala | e382ee2 | 2012-10-02 18:14:49 -0700 | [diff] [blame] | 354 | if (!haveQuirk) { | 
|  | 355 | result.appendFormat("    none\n"); | 
|  | 356 | } | 
|  | 357 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 358 | write(fd, result.string(), result.size()); | 
| Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 359 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 360 | mStreamingProcessor->dump(fd, args); | 
| Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 361 |  | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 362 | mCaptureSequencer->dump(fd, args); | 
|  | 363 |  | 
| Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 364 | mFrameProcessor->dump(fd, args); | 
|  | 365 |  | 
| Eino-Ville Talvala | 97b38a8 | 2012-09-17 17:55:07 -0700 | [diff] [blame] | 366 | mZslProcessor->dump(fd, args); | 
|  | 367 |  | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 368 | return dumpDevice(fd, args); | 
| Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 369 | #undef CASE_APPEND_ENUM | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 370 | } | 
|  | 371 |  | 
|  | 372 | // ICamera interface | 
|  | 373 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 374 | binder::Status Camera2Client::disconnect() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 375 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 376 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 377 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 378 | binder::Status res = binder::Status::ok(); | 
| Chien-Yu Chen | 98a668f | 2015-12-18 14:10:33 -0800 | [diff] [blame] | 379 | // Allow both client and the cameraserver to disconnect at all times | 
| Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 380 | int callingPid = getCallingPid(); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 381 | if (callingPid != mClientPid && callingPid != mServicePid) return res; | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 382 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 383 | if (mDevice == 0) return res; | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 384 |  | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 385 | ALOGV("Camera %d: Shutting down", mCameraId); | 
|  | 386 |  | 
| Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 387 | /** | 
|  | 388 | * disconnect() cannot call any methods that might need to promote a | 
|  | 389 | * wp<Camera2Client>, since disconnect can be called from the destructor, at | 
|  | 390 | * which point all such promotions will fail. | 
|  | 391 | */ | 
|  | 392 |  | 
| Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 393 | stopPreviewL(); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 394 |  | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 395 | { | 
|  | 396 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 397 | if (l.mParameters.state == Parameters::DISCONNECTED) return res; | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 398 | l.mParameters.state = Parameters::DISCONNECTED; | 
|  | 399 | } | 
|  | 400 |  | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 401 | mFrameProcessor->requestExit(); | 
|  | 402 | mCaptureSequencer->requestExit(); | 
|  | 403 | mJpegProcessor->requestExit(); | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 404 | mZslProcessor->requestExit(); | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 405 | mCallbackProcessor->requestExit(); | 
|  | 406 |  | 
|  | 407 | ALOGV("Camera %d: Waiting for threads", mCameraId); | 
|  | 408 |  | 
| Eino-Ville Talvala | 661c21d | 2014-10-22 14:21:12 -0700 | [diff] [blame] | 409 | { | 
|  | 410 | // Don't wait with lock held, in case the other threads need to | 
|  | 411 | // complete callbacks that re-enter Camera2Client | 
|  | 412 | mBinderSerializationLock.unlock(); | 
|  | 413 |  | 
| Eino-Ville Talvala | 661c21d | 2014-10-22 14:21:12 -0700 | [diff] [blame] | 414 | mFrameProcessor->join(); | 
|  | 415 | mCaptureSequencer->join(); | 
|  | 416 | mJpegProcessor->join(); | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 417 | mZslProcessor->join(); | 
| Eino-Ville Talvala | 661c21d | 2014-10-22 14:21:12 -0700 | [diff] [blame] | 418 | mCallbackProcessor->join(); | 
|  | 419 |  | 
|  | 420 | mBinderSerializationLock.lock(); | 
|  | 421 | } | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 422 |  | 
| Ruben Brunk | dfe7155 | 2013-12-05 11:00:37 -0800 | [diff] [blame] | 423 | ALOGV("Camera %d: Deleting streams", mCameraId); | 
|  | 424 |  | 
|  | 425 | mStreamingProcessor->deletePreviewStream(); | 
|  | 426 | mStreamingProcessor->deleteRecordingStream(); | 
|  | 427 | mJpegProcessor->deleteStream(); | 
|  | 428 | mCallbackProcessor->deleteStream(); | 
|  | 429 | mZslProcessor->deleteStream(); | 
|  | 430 |  | 
| Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 431 | ALOGV("Camera %d: Disconnecting device", mCameraId); | 
|  | 432 |  | 
|  | 433 | mDevice->disconnect(); | 
|  | 434 |  | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 435 | mDevice.clear(); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 436 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 437 | CameraService::Client::disconnect(); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 438 |  | 
|  | 439 | return res; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 440 | } | 
|  | 441 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 442 | status_t Camera2Client::connect(const sp<hardware::ICameraClient>& client) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 443 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 444 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 445 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 446 |  | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 447 | if (mClientPid != 0 && getCallingPid() != mClientPid) { | 
|  | 448 | ALOGE("%s: Camera %d: Connection attempt from pid %d; " | 
|  | 449 | "current locked to pid %d", __FUNCTION__, | 
|  | 450 | mCameraId, getCallingPid(), mClientPid); | 
|  | 451 | return BAD_VALUE; | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | mClientPid = getCallingPid(); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 455 |  | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 456 | mRemoteCallback = client; | 
|  | 457 | mSharedCameraCallbacks = client; | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 458 |  | 
|  | 459 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 460 | } | 
|  | 461 |  | 
|  | 462 | status_t Camera2Client::lock() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 463 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 464 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 465 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 466 | ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d", | 
|  | 467 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 468 |  | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 469 | if (mClientPid == 0) { | 
|  | 470 | mClientPid = getCallingPid(); | 
|  | 471 | return OK; | 
|  | 472 | } | 
|  | 473 |  | 
|  | 474 | if (mClientPid != getCallingPid()) { | 
|  | 475 | ALOGE("%s: Camera %d: Lock call from pid %d; currently locked to pid %d", | 
|  | 476 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); | 
|  | 477 | return EBUSY; | 
|  | 478 | } | 
|  | 479 |  | 
|  | 480 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 481 | } | 
|  | 482 |  | 
|  | 483 | status_t Camera2Client::unlock() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 484 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 485 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 486 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 487 | ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d", | 
|  | 488 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 489 |  | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 490 | if (mClientPid == getCallingPid()) { | 
| Eino-Ville Talvala | 907e565 | 2012-10-10 15:28:53 -0700 | [diff] [blame] | 491 | SharedParameters::Lock l(mParameters); | 
|  | 492 | if (l.mParameters.state == Parameters::RECORD || | 
|  | 493 | l.mParameters.state == Parameters::VIDEO_SNAPSHOT) { | 
|  | 494 | ALOGD("Not allowed to unlock camera during recording."); | 
|  | 495 | return INVALID_OPERATION; | 
|  | 496 | } | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 497 | mClientPid = 0; | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 498 | mRemoteCallback.clear(); | 
|  | 499 | mSharedCameraCallbacks.clear(); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 500 | return OK; | 
|  | 501 | } | 
|  | 502 |  | 
|  | 503 | ALOGE("%s: Camera %d: Unlock call from pid %d; currently locked to pid %d", | 
|  | 504 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); | 
|  | 505 | return EBUSY; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 506 | } | 
|  | 507 |  | 
| Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 508 | status_t Camera2Client::setPreviewTarget( | 
| Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 509 | const sp<IGraphicBufferProducer>& bufferProducer) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 510 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 511 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 512 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 513 | status_t res; | 
|  | 514 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 515 |  | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 516 | sp<IBinder> binder; | 
| Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 517 | sp<Surface> window; | 
| Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 518 | if (bufferProducer != 0) { | 
| Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 519 | binder = IInterface::asBinder(bufferProducer); | 
| Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 520 | // Using controlledByApp flag to ensure that the buffer queue remains in | 
|  | 521 | // async mode for the old camera API, where many applications depend | 
|  | 522 | // on that behavior. | 
|  | 523 | window = new Surface(bufferProducer, /*controlledByApp*/ true); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 524 | } | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 525 | return setPreviewWindowL(binder, window); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 526 | } | 
|  | 527 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 528 | status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder, | 
| Chih-Hung Hsieh | 5404ee1 | 2016-08-09 14:25:53 -0700 | [diff] [blame] | 529 | const sp<Surface>& window) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 530 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 531 | status_t res; | 
|  | 532 |  | 
|  | 533 | if (binder == mPreviewSurface) { | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 534 | ALOGV("%s: Camera %d: New window is same as old window", | 
|  | 535 | __FUNCTION__, mCameraId); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 536 | return NO_ERROR; | 
|  | 537 | } | 
|  | 538 |  | 
| Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 539 | Parameters::State state; | 
|  | 540 | { | 
|  | 541 | SharedParameters::Lock l(mParameters); | 
|  | 542 | state = l.mParameters.state; | 
|  | 543 | } | 
|  | 544 | switch (state) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 545 | case Parameters::DISCONNECTED: | 
|  | 546 | case Parameters::RECORD: | 
|  | 547 | case Parameters::STILL_CAPTURE: | 
|  | 548 | case Parameters::VIDEO_SNAPSHOT: | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 549 | ALOGE("%s: Camera %d: Cannot set preview display while in state %s", | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 550 | __FUNCTION__, mCameraId, | 
| Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 551 | Parameters::getStateName(state)); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 552 | return INVALID_OPERATION; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 553 | case Parameters::STOPPED: | 
|  | 554 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 555 | // OK | 
|  | 556 | break; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 557 | case Parameters::PREVIEW: | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 558 | // Already running preview - need to stop and create a new stream | 
| Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 559 | res = stopStream(); | 
|  | 560 | if (res != OK) { | 
|  | 561 | ALOGE("%s: Unable to stop preview to swap windows: %s (%d)", | 
|  | 562 | __FUNCTION__, strerror(-res), res); | 
|  | 563 | return res; | 
|  | 564 | } | 
| Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 565 | state = Parameters::WAITING_FOR_PREVIEW_WINDOW; | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 566 | break; | 
|  | 567 | } | 
|  | 568 |  | 
| Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 569 | mPreviewSurface = binder; | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 570 | res = mStreamingProcessor->setPreviewWindow(window); | 
|  | 571 | if (res != OK) { | 
|  | 572 | ALOGE("%s: Unable to set new preview window: %s (%d)", | 
|  | 573 | __FUNCTION__, strerror(-res), res); | 
|  | 574 | return res; | 
|  | 575 | } | 
| Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 576 |  | 
| Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 577 | if (state == Parameters::WAITING_FOR_PREVIEW_WINDOW) { | 
|  | 578 | SharedParameters::Lock l(mParameters); | 
|  | 579 | l.mParameters.state = state; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 580 | return startPreviewL(l.mParameters, false); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 581 | } | 
|  | 582 |  | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 583 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 584 | } | 
|  | 585 |  | 
|  | 586 | void Camera2Client::setPreviewCallbackFlag(int flag) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 587 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 588 | ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 589 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Igor Murashkin | ddf3c50 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 590 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 591 | if ( checkPid(__FUNCTION__) != OK) return; | 
|  | 592 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 593 | SharedParameters::Lock l(mParameters); | 
|  | 594 | setPreviewCallbackFlagL(l.mParameters, flag); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 595 | } | 
|  | 596 |  | 
|  | 597 | void Camera2Client::setPreviewCallbackFlagL(Parameters ¶ms, int flag) { | 
|  | 598 | status_t res = OK; | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 599 |  | 
|  | 600 | switch(params.state) { | 
|  | 601 | case Parameters::STOPPED: | 
|  | 602 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: | 
|  | 603 | case Parameters::PREVIEW: | 
| Zhijun He | a2520db | 2013-07-08 16:12:32 -0700 | [diff] [blame] | 604 | case Parameters::STILL_CAPTURE: | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 605 | // OK | 
|  | 606 | break; | 
|  | 607 | default: | 
|  | 608 | if (flag & CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK) { | 
|  | 609 | ALOGE("%s: Camera %d: Can't use preview callbacks " | 
|  | 610 | "in state %d", __FUNCTION__, mCameraId, params.state); | 
|  | 611 | return; | 
|  | 612 | } | 
|  | 613 | } | 
|  | 614 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 615 | if (flag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) { | 
|  | 616 | ALOGV("%s: setting oneshot", __FUNCTION__); | 
|  | 617 | params.previewCallbackOneShot = true; | 
|  | 618 | } | 
|  | 619 | if (params.previewCallbackFlags != (uint32_t)flag) { | 
| Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 620 |  | 
| Zhijun He | 527748a | 2013-09-15 21:06:10 -0700 | [diff] [blame] | 621 | if (params.previewCallbackSurface && flag != CAMERA_FRAME_CALLBACK_FLAG_NOOP) { | 
| Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 622 | // Disable any existing preview callback window when enabling | 
|  | 623 | // preview callback flags | 
|  | 624 | res = mCallbackProcessor->setCallbackWindow(NULL); | 
|  | 625 | if (res != OK) { | 
|  | 626 | ALOGE("%s: Camera %d: Unable to clear preview callback surface:" | 
|  | 627 | " %s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 628 | return; | 
|  | 629 | } | 
|  | 630 | params.previewCallbackSurface = false; | 
|  | 631 | } | 
|  | 632 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 633 | params.previewCallbackFlags = flag; | 
| Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 634 |  | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 635 | if (params.state == Parameters::PREVIEW) { | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 636 | res = startPreviewL(params, true); | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 637 | if (res != OK) { | 
|  | 638 | ALOGE("%s: Camera %d: Unable to refresh request in state %s", | 
|  | 639 | __FUNCTION__, mCameraId, | 
|  | 640 | Parameters::getStateName(params.state)); | 
|  | 641 | } | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 642 | } | 
|  | 643 | } | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 644 | } | 
|  | 645 |  | 
| Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 646 | status_t Camera2Client::setPreviewCallbackTarget( | 
|  | 647 | const sp<IGraphicBufferProducer>& callbackProducer) { | 
|  | 648 | ATRACE_CALL(); | 
|  | 649 | ALOGV("%s: E", __FUNCTION__); | 
|  | 650 | Mutex::Autolock icl(mBinderSerializationLock); | 
|  | 651 | status_t res; | 
|  | 652 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
|  | 653 |  | 
| Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 654 | sp<Surface> window; | 
| Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 655 | if (callbackProducer != 0) { | 
|  | 656 | window = new Surface(callbackProducer); | 
|  | 657 | } | 
|  | 658 |  | 
|  | 659 | res = mCallbackProcessor->setCallbackWindow(window); | 
|  | 660 | if (res != OK) { | 
|  | 661 | ALOGE("%s: Camera %d: Unable to set preview callback surface: %s (%d)", | 
|  | 662 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 663 | return res; | 
|  | 664 | } | 
|  | 665 |  | 
|  | 666 | SharedParameters::Lock l(mParameters); | 
|  | 667 |  | 
|  | 668 | if (window != NULL) { | 
|  | 669 | // Disable traditional callbacks when a valid callback target is given | 
|  | 670 | l.mParameters.previewCallbackFlags = CAMERA_FRAME_CALLBACK_FLAG_NOOP; | 
|  | 671 | l.mParameters.previewCallbackOneShot = false; | 
|  | 672 | l.mParameters.previewCallbackSurface = true; | 
|  | 673 | } else { | 
|  | 674 | // Disable callback target if given a NULL interface. | 
|  | 675 | l.mParameters.previewCallbackSurface = false; | 
|  | 676 | } | 
|  | 677 |  | 
|  | 678 | switch(l.mParameters.state) { | 
|  | 679 | case Parameters::PREVIEW: | 
|  | 680 | res = startPreviewL(l.mParameters, true); | 
|  | 681 | break; | 
|  | 682 | case Parameters::RECORD: | 
|  | 683 | case Parameters::VIDEO_SNAPSHOT: | 
|  | 684 | res = startRecordingL(l.mParameters, true); | 
|  | 685 | break; | 
|  | 686 | default: | 
|  | 687 | break; | 
|  | 688 | } | 
|  | 689 | if (res != OK) { | 
|  | 690 | ALOGE("%s: Camera %d: Unable to refresh request in state %s", | 
|  | 691 | __FUNCTION__, mCameraId, | 
|  | 692 | Parameters::getStateName(l.mParameters.state)); | 
|  | 693 | } | 
|  | 694 |  | 
|  | 695 | return OK; | 
|  | 696 | } | 
|  | 697 |  | 
|  | 698 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 699 | status_t Camera2Client::startPreview() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 700 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 701 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 702 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 703 | status_t res; | 
|  | 704 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 705 | SharedParameters::Lock l(mParameters); | 
|  | 706 | return startPreviewL(l.mParameters, false); | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 707 | } | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 708 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 709 | status_t Camera2Client::startPreviewL(Parameters ¶ms, bool restart) { | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 710 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 711 | status_t res; | 
| Igor Murashkin | 22d58d3 | 2012-10-02 19:07:14 -0700 | [diff] [blame] | 712 |  | 
|  | 713 | ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart); | 
|  | 714 |  | 
| Eino-Ville Talvala | a14be59 | 2012-10-10 17:17:01 -0700 | [diff] [blame] | 715 | if ( (params.state == Parameters::PREVIEW || | 
|  | 716 | params.state == Parameters::RECORD || | 
|  | 717 | params.state == Parameters::VIDEO_SNAPSHOT) | 
|  | 718 | && !restart) { | 
|  | 719 | // Succeed attempt to re-enter a streaming state | 
|  | 720 | ALOGI("%s: Camera %d: Preview already active, ignoring restart", | 
|  | 721 | __FUNCTION__, mCameraId); | 
| Alex Ray | 77449ad | 2012-09-26 15:52:50 -0700 | [diff] [blame] | 722 | return OK; | 
|  | 723 | } | 
|  | 724 | if (params.state > Parameters::PREVIEW && !restart) { | 
| Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 725 | ALOGE("%s: Can't start preview in state %s", | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 726 | __FUNCTION__, | 
|  | 727 | Parameters::getStateName(params.state)); | 
| Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 728 | return INVALID_OPERATION; | 
|  | 729 | } | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 730 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 731 | if (!mStreamingProcessor->haveValidPreviewWindow()) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 732 | params.state = Parameters::WAITING_FOR_PREVIEW_WINDOW; | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 733 | return OK; | 
|  | 734 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 735 | params.state = Parameters::STOPPED; | 
| Zhijun He | c1b7cc4 | 2014-01-21 12:15:56 -0800 | [diff] [blame] | 736 | int lastPreviewStreamId = mStreamingProcessor->getPreviewStreamId(); | 
| Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 737 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 738 | res = mStreamingProcessor->updatePreviewStream(params); | 
| Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 739 | if (res != OK) { | 
|  | 740 | ALOGE("%s: Camera %d: Unable to update preview stream: %s (%d)", | 
|  | 741 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 742 | return res; | 
|  | 743 | } | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 744 |  | 
| Zhijun He | c1b7cc4 | 2014-01-21 12:15:56 -0800 | [diff] [blame] | 745 | bool previewStreamChanged = mStreamingProcessor->getPreviewStreamId() != lastPreviewStreamId; | 
|  | 746 |  | 
| Eino-Ville Talvala | a9c64a9 | 2013-06-10 15:12:01 -0700 | [diff] [blame] | 747 | // We could wait to create the JPEG output stream until first actual use | 
|  | 748 | // (first takePicture call). However, this would substantially increase the | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 749 | // first capture latency on HAL3 devices. | 
|  | 750 | // So create it unconditionally at preview start. As a drawback, | 
| Eino-Ville Talvala | a9c64a9 | 2013-06-10 15:12:01 -0700 | [diff] [blame] | 751 | // this increases gralloc memory consumption for applications that don't | 
| Yin-Chia Yeh | 355d9c6 | 2015-02-24 15:51:43 -0800 | [diff] [blame] | 752 | // ever take a picture. Do not enter this mode when jpeg stream will slow | 
|  | 753 | // down preview. | 
| Eino-Ville Talvala | a9c64a9 | 2013-06-10 15:12:01 -0700 | [diff] [blame] | 754 | // TODO: Find a better compromise, though this likely would involve HAL | 
|  | 755 | // changes. | 
| Zhijun He | e2d8375 | 2014-06-23 10:22:37 -0700 | [diff] [blame] | 756 | int lastJpegStreamId = mJpegProcessor->getStreamId(); | 
| Yin-Chia Yeh | 355d9c6 | 2015-02-24 15:51:43 -0800 | [diff] [blame] | 757 | // If jpeg stream will slow down preview, make sure we remove it before starting preview | 
|  | 758 | if (params.slowJpegMode) { | 
|  | 759 | mJpegProcessor->deleteStream(); | 
|  | 760 | } else { | 
|  | 761 | res = updateProcessorStream(mJpegProcessor, params); | 
|  | 762 | if (res != OK) { | 
|  | 763 | ALOGE("%s: Camera %d: Can't pre-configure still image " | 
|  | 764 | "stream: %s (%d)", | 
|  | 765 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 766 | return res; | 
|  | 767 | } | 
| Eino-Ville Talvala | a9c64a9 | 2013-06-10 15:12:01 -0700 | [diff] [blame] | 768 | } | 
| Zhijun He | e2d8375 | 2014-06-23 10:22:37 -0700 | [diff] [blame] | 769 | bool jpegStreamChanged = mJpegProcessor->getStreamId() != lastJpegStreamId; | 
| Eino-Ville Talvala | a9c64a9 | 2013-06-10 15:12:01 -0700 | [diff] [blame] | 770 |  | 
| Zhijun He | d1d6467 | 2013-09-06 15:00:01 -0700 | [diff] [blame] | 771 | Vector<int32_t> outputStreams; | 
| Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 772 | bool callbacksEnabled = (params.previewCallbackFlags & | 
|  | 773 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK) || | 
|  | 774 | params.previewCallbackSurface; | 
|  | 775 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 776 | if (callbacksEnabled) { | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 777 | // Can't have recording stream hanging around when enabling callbacks, | 
|  | 778 | // since it exceeds the max stream count on some devices. | 
|  | 779 | if (mStreamingProcessor->getRecordingStreamId() != NO_STREAM) { | 
|  | 780 | ALOGV("%s: Camera %d: Clearing out recording stream before " | 
|  | 781 | "creating callback stream", __FUNCTION__, mCameraId); | 
|  | 782 | res = mStreamingProcessor->stopStream(); | 
|  | 783 | if (res != OK) { | 
|  | 784 | ALOGE("%s: Camera %d: Can't stop streaming to delete " | 
|  | 785 | "recording stream", __FUNCTION__, mCameraId); | 
|  | 786 | return res; | 
|  | 787 | } | 
|  | 788 | res = mStreamingProcessor->deleteRecordingStream(); | 
|  | 789 | if (res != OK) { | 
|  | 790 | ALOGE("%s: Camera %d: Unable to delete recording stream before " | 
|  | 791 | "enabling callbacks: %s (%d)", __FUNCTION__, mCameraId, | 
|  | 792 | strerror(-res), res); | 
|  | 793 | return res; | 
|  | 794 | } | 
|  | 795 | } | 
|  | 796 |  | 
| Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 797 | res = mCallbackProcessor->updateStream(params); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 798 | if (res != OK) { | 
|  | 799 | ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)", | 
|  | 800 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 801 | return res; | 
|  | 802 | } | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 803 | outputStreams.push(getCallbackStreamId()); | 
| Zhijun He | c1b7cc4 | 2014-01-21 12:15:56 -0800 | [diff] [blame] | 804 | } else if (previewStreamChanged && mCallbackProcessor->getStreamId() != NO_STREAM) { | 
|  | 805 | /** | 
|  | 806 | * Delete the unused callback stream when preview stream is changed and | 
|  | 807 | * preview is not enabled. Don't need stop preview stream as preview is in | 
|  | 808 | * STOPPED state now. | 
|  | 809 | */ | 
|  | 810 | ALOGV("%s: Camera %d: Delete unused preview callback stream.",  __FUNCTION__, mCameraId); | 
|  | 811 | res = mCallbackProcessor->deleteStream(); | 
|  | 812 | if (res != OK) { | 
|  | 813 | ALOGE("%s: Camera %d: Unable to delete callback stream %s (%d)", | 
|  | 814 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 815 | return res; | 
|  | 816 | } | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 817 | } | 
| Yin-Chia Yeh | ca05ebd | 2014-08-05 13:35:58 -0700 | [diff] [blame] | 818 |  | 
| Eino-Ville Talvala | c451d0f | 2016-06-30 17:17:35 -0700 | [diff] [blame] | 819 | if (params.useZeroShutterLag() && | 
| Yin-Chia Yeh | ca05ebd | 2014-08-05 13:35:58 -0700 | [diff] [blame] | 820 | getRecordingStreamId() == NO_STREAM) { | 
| Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 821 | res = updateProcessorStream(mZslProcessor, params); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 822 | if (res != OK) { | 
|  | 823 | ALOGE("%s: Camera %d: Unable to update ZSL stream: %s (%d)", | 
|  | 824 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 825 | return res; | 
|  | 826 | } | 
| Zhijun He | e2d8375 | 2014-06-23 10:22:37 -0700 | [diff] [blame] | 827 |  | 
|  | 828 | if (jpegStreamChanged) { | 
|  | 829 | ALOGV("%s: Camera %d: Clear ZSL buffer queue when Jpeg size is changed", | 
|  | 830 | __FUNCTION__, mCameraId); | 
|  | 831 | mZslProcessor->clearZslQueue(); | 
|  | 832 | } | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 833 | outputStreams.push(getZslStreamId()); | 
| Zhijun He | 6610762 | 2013-11-01 11:05:56 -0700 | [diff] [blame] | 834 | } else { | 
|  | 835 | mZslProcessor->deleteStream(); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 836 | } | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 837 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 838 | outputStreams.push(getPreviewStreamId()); | 
|  | 839 |  | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 840 | if (!params.recordingHint) { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 841 | if (!restart) { | 
|  | 842 | res = mStreamingProcessor->updatePreviewRequest(params); | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 843 | if (res != OK) { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 844 | ALOGE("%s: Camera %d: Can't set up preview request: " | 
|  | 845 | "%s (%d)", __FUNCTION__, mCameraId, | 
|  | 846 | strerror(-res), res); | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 847 | return res; | 
|  | 848 | } | 
|  | 849 | } | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 850 | res = mStreamingProcessor->startStream(StreamingProcessor::PREVIEW, | 
|  | 851 | outputStreams); | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 852 | } else { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 853 | if (!restart) { | 
|  | 854 | res = mStreamingProcessor->updateRecordingRequest(params); | 
|  | 855 | if (res != OK) { | 
|  | 856 | ALOGE("%s: Camera %d: Can't set up preview request with " | 
|  | 857 | "record hint: %s (%d)", __FUNCTION__, mCameraId, | 
|  | 858 | strerror(-res), res); | 
|  | 859 | return res; | 
|  | 860 | } | 
|  | 861 | } | 
|  | 862 | res = mStreamingProcessor->startStream(StreamingProcessor::RECORD, | 
|  | 863 | outputStreams); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 864 | } | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 865 | if (res != OK) { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 866 | ALOGE("%s: Camera %d: Unable to start streaming preview: %s (%d)", | 
| Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 867 | __FUNCTION__, mCameraId, strerror(-res), res); | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 868 | return res; | 
|  | 869 | } | 
|  | 870 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 871 | params.state = Parameters::PREVIEW; | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 872 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 873 | } | 
|  | 874 |  | 
|  | 875 | void Camera2Client::stopPreview() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 876 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 877 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 878 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 879 | status_t res; | 
|  | 880 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 881 | stopPreviewL(); | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 882 | } | 
|  | 883 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 884 | void Camera2Client::stopPreviewL() { | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 885 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 886 | status_t res; | 
| Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 887 | const nsecs_t kStopCaptureTimeout = 3000000000LL; // 3 seconds | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 888 | Parameters::State state; | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 889 | { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 890 | SharedParameters::Lock l(mParameters); | 
|  | 891 | state = l.mParameters.state; | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 892 | } | 
|  | 893 |  | 
|  | 894 | switch (state) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 895 | case Parameters::DISCONNECTED: | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 896 | // Nothing to do. | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 897 | break; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 898 | case Parameters::STOPPED: | 
| Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 899 | case Parameters::VIDEO_SNAPSHOT: | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 900 | case Parameters::STILL_CAPTURE: | 
| Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 901 | mCaptureSequencer->waitUntilIdle(kStopCaptureTimeout); | 
|  | 902 | // no break | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 903 | case Parameters::RECORD: | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 904 | case Parameters::PREVIEW: | 
| Ruben Brunk | a27c4aa | 2013-09-04 18:18:26 -0700 | [diff] [blame] | 905 | syncWithDevice(); | 
| Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 906 | res = stopStream(); | 
|  | 907 | if (res != OK) { | 
|  | 908 | ALOGE("%s: Camera %d: Can't stop streaming: %s (%d)", | 
|  | 909 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 910 | } | 
| Ruchit Sharma | 2cec0df | 2014-08-20 16:02:08 -0400 | [diff] [blame] | 911 |  | 
|  | 912 | // Flush all in-process captures and buffer in order to stop | 
|  | 913 | // preview faster. | 
|  | 914 | res = mDevice->flush(); | 
|  | 915 | if (res != OK) { | 
|  | 916 | ALOGE("%s: Camera %d: Unable to flush pending requests: %s (%d)", | 
|  | 917 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 918 | } | 
|  | 919 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 920 | res = mDevice->waitUntilDrained(); | 
|  | 921 | if (res != OK) { | 
|  | 922 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)", | 
|  | 923 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 924 | } | 
| Yin-Chia Yeh | 28d0327 | 2014-07-17 16:05:23 -0700 | [diff] [blame] | 925 | // Clean up recording stream | 
|  | 926 | res = mStreamingProcessor->deleteRecordingStream(); | 
|  | 927 | if (res != OK) { | 
|  | 928 | ALOGE("%s: Camera %d: Unable to delete recording stream before " | 
|  | 929 | "stop preview: %s (%d)", | 
|  | 930 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 931 | } | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 932 | // no break | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 933 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: { | 
|  | 934 | SharedParameters::Lock l(mParameters); | 
|  | 935 | l.mParameters.state = Parameters::STOPPED; | 
|  | 936 | commandStopFaceDetectionL(l.mParameters); | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 937 | break; | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 938 | } | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 939 | default: | 
|  | 940 | ALOGE("%s: Camera %d: Unknown state %d", __FUNCTION__, mCameraId, | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 941 | state); | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 942 | } | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 943 | } | 
|  | 944 |  | 
|  | 945 | bool Camera2Client::previewEnabled() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 946 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 947 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 948 | status_t res; | 
|  | 949 | if ( (res = checkPid(__FUNCTION__) ) != OK) return false; | 
|  | 950 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 951 | SharedParameters::Lock l(mParameters); | 
|  | 952 | return l.mParameters.state == Parameters::PREVIEW; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 953 | } | 
|  | 954 |  | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 955 | status_t Camera2Client::setVideoBufferMode(int32_t videoBufferMode) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 956 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 957 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 958 | status_t res; | 
|  | 959 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
|  | 960 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 961 | SharedParameters::Lock l(mParameters); | 
|  | 962 | switch (l.mParameters.state) { | 
|  | 963 | case Parameters::RECORD: | 
|  | 964 | case Parameters::VIDEO_SNAPSHOT: | 
| Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 965 | ALOGE("%s: Camera %d: Can't be called in state %s", | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 966 | __FUNCTION__, mCameraId, | 
|  | 967 | Parameters::getStateName(l.mParameters.state)); | 
| Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 968 | return INVALID_OPERATION; | 
|  | 969 | default: | 
|  | 970 | // OK | 
|  | 971 | break; | 
|  | 972 | } | 
| Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 973 |  | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 974 | if (videoBufferMode != VIDEO_BUFFER_MODE_BUFFER_QUEUE) { | 
|  | 975 | ALOGE("%s: %d: Only video buffer queue is supported", __FUNCTION__, __LINE__); | 
|  | 976 | return BAD_VALUE; | 
|  | 977 | } | 
|  | 978 |  | 
|  | 979 | l.mParameters.videoBufferMode = videoBufferMode; | 
| Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 980 |  | 
|  | 981 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 982 | } | 
|  | 983 |  | 
|  | 984 | status_t Camera2Client::startRecording() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 985 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 986 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 987 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 988 | status_t res; | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 989 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 990 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 991 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 992 | return startRecordingL(l.mParameters, false); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 993 | } | 
|  | 994 |  | 
|  | 995 | status_t Camera2Client::startRecordingL(Parameters ¶ms, bool restart) { | 
|  | 996 | status_t res; | 
| Igor Murashkin | 22d58d3 | 2012-10-02 19:07:14 -0700 | [diff] [blame] | 997 |  | 
|  | 998 | ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart); | 
|  | 999 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1000 | switch (params.state) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1001 | case Parameters::STOPPED: | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1002 | res = startPreviewL(params, false); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1003 | if (res != OK) return res; | 
| Zhijun He | 96ff5c4 | 2014-10-13 22:20:37 -0700 | [diff] [blame] | 1004 | // Make sure first preview request is submitted to the HAL device to avoid | 
|  | 1005 | // two consecutive set of configure_streams being called into the HAL. | 
|  | 1006 | // TODO: Refactor this to avoid initial preview configuration. | 
|  | 1007 | syncWithDevice(); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1008 | break; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1009 | case Parameters::PREVIEW: | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1010 | // Ready to go | 
|  | 1011 | break; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1012 | case Parameters::RECORD: | 
|  | 1013 | case Parameters::VIDEO_SNAPSHOT: | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1014 | // OK to call this when recording is already on, just skip unless | 
|  | 1015 | // we're looking to restart | 
|  | 1016 | if (!restart) return OK; | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1017 | break; | 
|  | 1018 | default: | 
|  | 1019 | ALOGE("%s: Camera %d: Can't start recording in state %s", | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1020 | __FUNCTION__, mCameraId, | 
|  | 1021 | Parameters::getStateName(params.state)); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1022 | return INVALID_OPERATION; | 
|  | 1023 | }; | 
|  | 1024 |  | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 1025 | if (params.videoBufferMode != VIDEO_BUFFER_MODE_BUFFER_QUEUE) { | 
|  | 1026 | ALOGE("%s: Camera %d: Recording only supported buffer queue mode, but " | 
|  | 1027 | "mode %d is requested!", __FUNCTION__, mCameraId, params.videoBufferMode); | 
|  | 1028 | return INVALID_OPERATION; | 
|  | 1029 | } | 
|  | 1030 |  | 
|  | 1031 | if (!mStreamingProcessor->haveValidRecordingWindow()) { | 
|  | 1032 | ALOGE("%s: No valid recording window", __FUNCTION__); | 
| Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 1033 | return INVALID_OPERATION; | 
|  | 1034 | } | 
|  | 1035 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1036 | if (!restart) { | 
| Chien-Yu Chen | 82104eb | 2015-10-14 11:29:31 -0700 | [diff] [blame] | 1037 | mCameraService->playSound(CameraService::SOUND_RECORDING_START); | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1038 | mStreamingProcessor->updateRecordingRequest(params); | 
|  | 1039 | if (res != OK) { | 
|  | 1040 | ALOGE("%s: Camera %d: Unable to update recording request: %s (%d)", | 
|  | 1041 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1042 | return res; | 
|  | 1043 | } | 
|  | 1044 | } | 
| Eino-Ville Talvala | 609acc0 | 2012-09-06 18:26:58 -0700 | [diff] [blame] | 1045 |  | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 1046 | // Not all devices can support a preview callback stream and a recording | 
|  | 1047 | // stream at the same time, so assume none of them can. | 
|  | 1048 | if (mCallbackProcessor->getStreamId() != NO_STREAM) { | 
|  | 1049 | ALOGV("%s: Camera %d: Clearing out callback stream before " | 
|  | 1050 | "creating recording stream", __FUNCTION__, mCameraId); | 
|  | 1051 | res = mStreamingProcessor->stopStream(); | 
|  | 1052 | if (res != OK) { | 
|  | 1053 | ALOGE("%s: Camera %d: Can't stop streaming to delete callback stream", | 
|  | 1054 | __FUNCTION__, mCameraId); | 
|  | 1055 | return res; | 
|  | 1056 | } | 
|  | 1057 | res = mCallbackProcessor->deleteStream(); | 
|  | 1058 | if (res != OK) { | 
|  | 1059 | ALOGE("%s: Camera %d: Unable to delete callback stream before " | 
|  | 1060 | "record: %s (%d)", __FUNCTION__, mCameraId, | 
|  | 1061 | strerror(-res), res); | 
|  | 1062 | return res; | 
|  | 1063 | } | 
|  | 1064 | } | 
| Yin-Chia Yeh | ca05ebd | 2014-08-05 13:35:58 -0700 | [diff] [blame] | 1065 |  | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 1066 | // Clean up ZSL before transitioning into recording | 
|  | 1067 | if (mZslProcessor->getStreamId() != NO_STREAM) { | 
|  | 1068 | ALOGV("%s: Camera %d: Clearing out zsl stream before " | 
|  | 1069 | "creating recording stream", __FUNCTION__, mCameraId); | 
|  | 1070 | res = mStreamingProcessor->stopStream(); | 
|  | 1071 | if (res != OK) { | 
|  | 1072 | ALOGE("%s: Camera %d: Can't stop streaming to delete callback stream", | 
|  | 1073 | __FUNCTION__, mCameraId); | 
|  | 1074 | return res; | 
|  | 1075 | } | 
|  | 1076 | res = mDevice->waitUntilDrained(); | 
|  | 1077 | if (res != OK) { | 
|  | 1078 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)", | 
|  | 1079 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1080 | } | 
|  | 1081 | res = mZslProcessor->clearZslQueue(); | 
|  | 1082 | if (res != OK) { | 
|  | 1083 | ALOGE("%s: Camera %d: Can't clear zsl queue", | 
|  | 1084 | __FUNCTION__, mCameraId); | 
|  | 1085 | return res; | 
|  | 1086 | } | 
|  | 1087 | res = mZslProcessor->deleteStream(); | 
|  | 1088 | if (res != OK) { | 
|  | 1089 | ALOGE("%s: Camera %d: Unable to delete zsl stream before " | 
|  | 1090 | "record: %s (%d)", __FUNCTION__, mCameraId, | 
|  | 1091 | strerror(-res), res); | 
|  | 1092 | return res; | 
| Yin-Chia Yeh | ca05ebd | 2014-08-05 13:35:58 -0700 | [diff] [blame] | 1093 | } | 
|  | 1094 | } | 
|  | 1095 |  | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 1096 | // Disable callbacks if they're enabled; can't record and use callbacks, | 
|  | 1097 | // and we can't fail record start without stagefright asserting. | 
|  | 1098 | params.previewCallbackFlags = 0; | 
|  | 1099 |  | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 1100 | // May need to reconfigure video snapshot JPEG sizes | 
|  | 1101 | // during recording startup, so need a more complex sequence here to | 
|  | 1102 | // ensure an early stream reconfiguration doesn't happen | 
|  | 1103 | bool recordingStreamNeedsUpdate; | 
|  | 1104 | res = mStreamingProcessor->recordingStreamNeedsUpdate(params, &recordingStreamNeedsUpdate); | 
|  | 1105 | if (res != OK) { | 
|  | 1106 | ALOGE("%s: Camera %d: Can't query recording stream", | 
|  | 1107 | __FUNCTION__, mCameraId); | 
|  | 1108 | return res; | 
|  | 1109 | } | 
|  | 1110 |  | 
|  | 1111 | if (recordingStreamNeedsUpdate) { | 
|  | 1112 | // Need to stop stream here so updateProcessorStream won't trigger configureStream | 
|  | 1113 | // Right now camera device cannot handle configureStream failure gracefully | 
|  | 1114 | // when device is streaming | 
|  | 1115 | res = mStreamingProcessor->stopStream(); | 
| Yin-Chia Yeh | a53021f | 2014-09-12 14:50:27 -0700 | [diff] [blame] | 1116 | if (res != OK) { | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 1117 | ALOGE("%s: Camera %d: Can't stop streaming to update record " | 
|  | 1118 | "stream", __FUNCTION__, mCameraId); | 
| Yin-Chia Yeh | a53021f | 2014-09-12 14:50:27 -0700 | [diff] [blame] | 1119 | return res; | 
|  | 1120 | } | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 1121 | res = mDevice->waitUntilDrained(); | 
| Yin-Chia Yeh | a53021f | 2014-09-12 14:50:27 -0700 | [diff] [blame] | 1122 | if (res != OK) { | 
| Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 1123 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: " | 
|  | 1124 | "%s (%d)", __FUNCTION__, mCameraId, | 
|  | 1125 | strerror(-res), res); | 
|  | 1126 | } | 
|  | 1127 |  | 
|  | 1128 | res = updateProcessorStream< | 
|  | 1129 | StreamingProcessor, | 
|  | 1130 | &StreamingProcessor::updateRecordingStream>( | 
|  | 1131 | mStreamingProcessor, | 
|  | 1132 | params); | 
|  | 1133 | if (res != OK) { | 
|  | 1134 | ALOGE("%s: Camera %d: Unable to update recording stream: " | 
|  | 1135 | "%s (%d)", __FUNCTION__, mCameraId, | 
|  | 1136 | strerror(-res), res); | 
| Yin-Chia Yeh | a53021f | 2014-09-12 14:50:27 -0700 | [diff] [blame] | 1137 | return res; | 
|  | 1138 | } | 
|  | 1139 | } | 
|  | 1140 |  | 
| Zhijun He | d1d6467 | 2013-09-06 15:00:01 -0700 | [diff] [blame] | 1141 | Vector<int32_t> outputStreams; | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1142 | outputStreams.push(getPreviewStreamId()); | 
|  | 1143 | outputStreams.push(getRecordingStreamId()); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1144 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1145 | res = mStreamingProcessor->startStream(StreamingProcessor::RECORD, | 
|  | 1146 | outputStreams); | 
| Yin-Chia Yeh | 3ea3fcd | 2014-09-05 14:14:44 -0700 | [diff] [blame] | 1147 |  | 
| Yin-Chia Yeh | a53021f | 2014-09-12 14:50:27 -0700 | [diff] [blame] | 1148 | // startStream might trigger a configureStream call and device might fail | 
|  | 1149 | // configureStream due to jpeg size > video size. Try again with jpeg size overridden | 
|  | 1150 | // to video size. | 
|  | 1151 | if (res == BAD_VALUE) { | 
|  | 1152 | overrideVideoSnapshotSize(params); | 
| Yin-Chia Yeh | 3ea3fcd | 2014-09-05 14:14:44 -0700 | [diff] [blame] | 1153 | res = mStreamingProcessor->startStream(StreamingProcessor::RECORD, | 
|  | 1154 | outputStreams); | 
|  | 1155 | } | 
|  | 1156 |  | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1157 | if (res != OK) { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1158 | ALOGE("%s: Camera %d: Unable to start recording stream: %s (%d)", | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1159 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1160 | return res; | 
|  | 1161 | } | 
|  | 1162 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1163 | if (params.state < Parameters::RECORD) { | 
|  | 1164 | params.state = Parameters::RECORD; | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1165 | } | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1166 |  | 
|  | 1167 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1168 | } | 
|  | 1169 |  | 
|  | 1170 | void Camera2Client::stopRecording() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1171 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 1172 | ALOGV("%s: E", __FUNCTION__); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1173 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1174 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1175 |  | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1176 | status_t res; | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1177 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; | 
|  | 1178 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1179 | switch (l.mParameters.state) { | 
|  | 1180 | case Parameters::RECORD: | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1181 | // OK to stop | 
|  | 1182 | break; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1183 | case Parameters::STOPPED: | 
|  | 1184 | case Parameters::PREVIEW: | 
|  | 1185 | case Parameters::STILL_CAPTURE: | 
|  | 1186 | case Parameters::VIDEO_SNAPSHOT: | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1187 | default: | 
|  | 1188 | ALOGE("%s: Camera %d: Can't stop recording in state %s", | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1189 | __FUNCTION__, mCameraId, | 
|  | 1190 | Parameters::getStateName(l.mParameters.state)); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1191 | return; | 
|  | 1192 | }; | 
|  | 1193 |  | 
| Chien-Yu Chen | 82104eb | 2015-10-14 11:29:31 -0700 | [diff] [blame] | 1194 | mCameraService->playSound(CameraService::SOUND_RECORDING_STOP); | 
| Eino-Ville Talvala | 609acc0 | 2012-09-06 18:26:58 -0700 | [diff] [blame] | 1195 |  | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 1196 | // Remove recording stream because the video target may be abandoned soon. | 
|  | 1197 | res = stopStream(); | 
|  | 1198 | if (res != OK) { | 
|  | 1199 | ALOGE("%s: Camera %d: Can't stop streaming: %s (%d)", | 
|  | 1200 | __FUNCTION__, mCameraId, strerror(-res), res); | 
| Yin-Chia Yeh | 092d49c | 2014-11-06 15:40:13 -0800 | [diff] [blame] | 1201 | } | 
|  | 1202 |  | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 1203 | res = mDevice->waitUntilDrained(); | 
|  | 1204 | if (res != OK) { | 
|  | 1205 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)", | 
|  | 1206 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1207 | } | 
|  | 1208 | // Clean up recording stream | 
|  | 1209 | res = mStreamingProcessor->deleteRecordingStream(); | 
|  | 1210 | if (res != OK) { | 
|  | 1211 | ALOGE("%s: Camera %d: Unable to delete recording stream before " | 
|  | 1212 | "stop preview: %s (%d)", | 
|  | 1213 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1214 | } | 
|  | 1215 | l.mParameters.recoverOverriddenJpegSize(); | 
|  | 1216 |  | 
|  | 1217 | // Restart preview | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 1218 | res = startPreviewL(l.mParameters, true); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1219 | if (res != OK) { | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 1220 | ALOGE("%s: Camera %d: Unable to return to preview", | 
|  | 1221 | __FUNCTION__, mCameraId); | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1222 | } | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1223 | } | 
|  | 1224 |  | 
|  | 1225 | bool Camera2Client::recordingEnabled() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1226 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1227 | Mutex::Autolock icl(mBinderSerializationLock); | 
| James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 1228 |  | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1229 | if ( checkPid(__FUNCTION__) != OK) return false; | 
|  | 1230 |  | 
| James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 1231 | return recordingEnabledL(); | 
|  | 1232 | } | 
|  | 1233 |  | 
|  | 1234 | bool Camera2Client::recordingEnabledL() { | 
|  | 1235 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1236 | SharedParameters::Lock l(mParameters); | 
| James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 1237 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1238 | return (l.mParameters.state == Parameters::RECORD | 
|  | 1239 | || l.mParameters.state == Parameters::VIDEO_SNAPSHOT); | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1240 | } | 
|  | 1241 |  | 
|  | 1242 | void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { | 
| Chien-Yu Chen | 98a668f | 2015-12-18 14:10:33 -0800 | [diff] [blame] | 1243 | (void)mem; | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1244 | ATRACE_CALL(); | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 1245 | ALOGW("%s: Not supported in buffer queue mode.", __FUNCTION__); | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1246 | } | 
|  | 1247 |  | 
| Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 1248 | void Camera2Client::releaseRecordingFrameHandle(native_handle_t *handle) { | 
|  | 1249 | (void)handle; | 
|  | 1250 | ATRACE_CALL(); | 
|  | 1251 | ALOGW("%s: Not supported in buffer queue mode.", __FUNCTION__); | 
|  | 1252 | } | 
|  | 1253 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1254 | status_t Camera2Client::autoFocus() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1255 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1256 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1257 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1258 | status_t res; | 
|  | 1259 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
|  | 1260 |  | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1261 | int triggerId; | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1262 | bool notifyImmediately = false; | 
|  | 1263 | bool notifySuccess = false; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1264 | { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1265 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1266 | if (l.mParameters.state < Parameters::PREVIEW) { | 
| Zhijun He | f79f8ca | 2014-09-22 23:52:54 -0700 | [diff] [blame] | 1267 | ALOGE("%s: Camera %d: Call autoFocus when preview is inactive (state = %d).", | 
|  | 1268 | __FUNCTION__, mCameraId, l.mParameters.state); | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1269 | return INVALID_OPERATION; | 
|  | 1270 | } | 
|  | 1271 |  | 
| Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1272 | /** | 
|  | 1273 | * If the camera does not support auto-focus, it is a no-op and | 
|  | 1274 | * onAutoFocus(boolean, Camera) callback will be called immediately | 
|  | 1275 | * with a fake value of success set to true. | 
| Eino-Ville Talvala | 9454a97 | 2013-06-03 16:50:53 -0700 | [diff] [blame] | 1276 | * | 
|  | 1277 | * Similarly, if focus mode is set to INFINITY, there's no reason to | 
|  | 1278 | * bother the HAL. | 
| Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1279 | */ | 
| Eino-Ville Talvala | 9454a97 | 2013-06-03 16:50:53 -0700 | [diff] [blame] | 1280 | if (l.mParameters.focusMode == Parameters::FOCUS_MODE_FIXED || | 
|  | 1281 | l.mParameters.focusMode == Parameters::FOCUS_MODE_INFINITY) { | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1282 | notifyImmediately = true; | 
|  | 1283 | notifySuccess = true; | 
|  | 1284 | } | 
|  | 1285 | /** | 
|  | 1286 | * If we're in CAF mode, and AF has already been locked, just fire back | 
|  | 1287 | * the callback right away; the HAL would not send a notification since | 
|  | 1288 | * no state change would happen on a AF trigger. | 
|  | 1289 | */ | 
|  | 1290 | if ( (l.mParameters.focusMode == Parameters::FOCUS_MODE_CONTINUOUS_PICTURE || | 
|  | 1291 | l.mParameters.focusMode == Parameters::FOCUS_MODE_CONTINUOUS_VIDEO) && | 
|  | 1292 | l.mParameters.focusState == ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED ) { | 
|  | 1293 | notifyImmediately = true; | 
|  | 1294 | notifySuccess = true; | 
|  | 1295 | } | 
|  | 1296 | /** | 
|  | 1297 | * Send immediate notification back to client | 
|  | 1298 | */ | 
|  | 1299 | if (notifyImmediately) { | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1300 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); | 
|  | 1301 | if (l.mRemoteCallback != 0) { | 
|  | 1302 | l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1303 | notifySuccess ? 1 : 0, 0); | 
| Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1304 | } | 
| Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1305 | return OK; | 
|  | 1306 | } | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1307 | /** | 
|  | 1308 | * Handle quirk mode for AF in scene modes | 
|  | 1309 | */ | 
| Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1310 | if (l.mParameters.quirks.triggerAfWithAuto && | 
| Ruben Brunk | c69b91c | 2014-01-17 17:12:10 -0800 | [diff] [blame] | 1311 | l.mParameters.sceneMode != ANDROID_CONTROL_SCENE_MODE_DISABLED && | 
| Eino-Ville Talvala | ac0cd56 | 2012-10-16 12:58:21 -0700 | [diff] [blame] | 1312 | l.mParameters.focusMode != Parameters::FOCUS_MODE_AUTO && | 
|  | 1313 | !l.mParameters.focusingAreas[0].isEmpty()) { | 
| Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1314 | ALOGV("%s: Quirk: Switching from focusMode %d to AUTO", | 
|  | 1315 | __FUNCTION__, l.mParameters.focusMode); | 
|  | 1316 | l.mParameters.shadowFocusMode = l.mParameters.focusMode; | 
|  | 1317 | l.mParameters.focusMode = Parameters::FOCUS_MODE_AUTO; | 
|  | 1318 | updateRequests(l.mParameters); | 
|  | 1319 | } | 
|  | 1320 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1321 | l.mParameters.currentAfTriggerId = ++l.mParameters.afTriggerCounter; | 
|  | 1322 | triggerId = l.mParameters.currentAfTriggerId; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1323 | } | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1324 | ATRACE_ASYNC_BEGIN(kAutofocusLabel, triggerId); | 
|  | 1325 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1326 | syncWithDevice(); | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1327 |  | 
|  | 1328 | mDevice->triggerAutofocus(triggerId); | 
|  | 1329 |  | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1330 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1331 | } | 
|  | 1332 |  | 
|  | 1333 | status_t Camera2Client::cancelAutoFocus() { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1334 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1335 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1336 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1337 | status_t res; | 
|  | 1338 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
|  | 1339 |  | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1340 | int triggerId; | 
|  | 1341 | { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1342 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 9454a97 | 2013-06-03 16:50:53 -0700 | [diff] [blame] | 1343 | // Canceling does nothing in FIXED or INFINITY modes | 
|  | 1344 | if (l.mParameters.focusMode == Parameters::FOCUS_MODE_FIXED || | 
|  | 1345 | l.mParameters.focusMode == Parameters::FOCUS_MODE_INFINITY) { | 
|  | 1346 | return OK; | 
|  | 1347 | } | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1348 |  | 
|  | 1349 | // An active AF trigger is canceled | 
|  | 1350 | if (l.mParameters.afTriggerCounter == l.mParameters.currentAfTriggerId) { | 
|  | 1351 | ATRACE_ASYNC_END(kAutofocusLabel, l.mParameters.currentAfTriggerId); | 
|  | 1352 | } | 
|  | 1353 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1354 | triggerId = ++l.mParameters.afTriggerCounter; | 
| Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1355 |  | 
|  | 1356 | // When using triggerAfWithAuto quirk, may need to reset focus mode to | 
| Eino-Ville Talvala | ac0cd56 | 2012-10-16 12:58:21 -0700 | [diff] [blame] | 1357 | // the real state at this point. No need to cancel explicitly if | 
|  | 1358 | // changing the AF mode. | 
| Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1359 | if (l.mParameters.shadowFocusMode != Parameters::FOCUS_MODE_INVALID) { | 
|  | 1360 | ALOGV("%s: Quirk: Restoring focus mode to %d", __FUNCTION__, | 
|  | 1361 | l.mParameters.shadowFocusMode); | 
|  | 1362 | l.mParameters.focusMode = l.mParameters.shadowFocusMode; | 
|  | 1363 | l.mParameters.shadowFocusMode = Parameters::FOCUS_MODE_INVALID; | 
|  | 1364 | updateRequests(l.mParameters); | 
| Eino-Ville Talvala | ac0cd56 | 2012-10-16 12:58:21 -0700 | [diff] [blame] | 1365 |  | 
|  | 1366 | return OK; | 
| Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1367 | } | 
| Eino-Ville Talvala | c451d0f | 2016-06-30 17:17:35 -0700 | [diff] [blame] | 1368 | if (l.mParameters.allowZslMode) { | 
| Yin-Chia Yeh | dec84fb | 2014-09-10 15:14:18 -0700 | [diff] [blame] | 1369 | mZslProcessor->clearZslQueue(); | 
|  | 1370 | } | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1371 | } | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1372 | syncWithDevice(); | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1373 |  | 
|  | 1374 | mDevice->triggerCancelAutofocus(triggerId); | 
|  | 1375 |  | 
| Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1376 | return OK; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1377 | } | 
|  | 1378 |  | 
| Ben Murdoch | ff82370 | 2012-11-28 13:58:29 +0000 | [diff] [blame] | 1379 | status_t Camera2Client::takePicture(int msgType) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1380 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1381 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1382 | status_t res; | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1383 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1384 |  | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1385 | int takePictureCounter; | 
| Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1386 | { | 
|  | 1387 | SharedParameters::Lock l(mParameters); | 
|  | 1388 | switch (l.mParameters.state) { | 
|  | 1389 | case Parameters::DISCONNECTED: | 
|  | 1390 | case Parameters::STOPPED: | 
|  | 1391 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: | 
|  | 1392 | ALOGE("%s: Camera %d: Cannot take picture without preview enabled", | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1393 | __FUNCTION__, mCameraId); | 
| Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1394 | return INVALID_OPERATION; | 
|  | 1395 | case Parameters::PREVIEW: | 
|  | 1396 | // Good to go for takePicture | 
|  | 1397 | res = commandStopFaceDetectionL(l.mParameters); | 
|  | 1398 | if (res != OK) { | 
|  | 1399 | ALOGE("%s: Camera %d: Unable to stop face detection for still capture", | 
|  | 1400 | __FUNCTION__, mCameraId); | 
|  | 1401 | return res; | 
|  | 1402 | } | 
|  | 1403 | l.mParameters.state = Parameters::STILL_CAPTURE; | 
| Yin-Chia Yeh | 092d49c | 2014-11-06 15:40:13 -0800 | [diff] [blame] | 1404 |  | 
|  | 1405 | // Remove recording stream to prevent video snapshot jpeg logic kicking in | 
|  | 1406 | if (l.mParameters.isJpegSizeOverridden() && | 
|  | 1407 | mStreamingProcessor->getRecordingStreamId() != NO_STREAM) { | 
|  | 1408 | res = mStreamingProcessor->togglePauseStream(/*pause*/true); | 
|  | 1409 | if (res != OK) { | 
|  | 1410 | ALOGE("%s: Camera %d: Can't pause streaming: %s (%d)", | 
|  | 1411 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1412 | } | 
|  | 1413 | res = mDevice->waitUntilDrained(); | 
|  | 1414 | if (res != OK) { | 
|  | 1415 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)", | 
|  | 1416 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1417 | } | 
|  | 1418 | // Clean up recording stream | 
|  | 1419 | res = mStreamingProcessor->deleteRecordingStream(); | 
|  | 1420 | if (res != OK) { | 
|  | 1421 | ALOGE("%s: Camera %d: Unable to delete recording stream before " | 
|  | 1422 | "stop preview: %s (%d)", | 
|  | 1423 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1424 | } | 
|  | 1425 | res = mStreamingProcessor->togglePauseStream(/*pause*/false); | 
|  | 1426 | if (res != OK) { | 
|  | 1427 | ALOGE("%s: Camera %d: Can't unpause streaming: %s (%d)", | 
|  | 1428 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1429 | } | 
|  | 1430 | l.mParameters.recoverOverriddenJpegSize(); | 
|  | 1431 | } | 
| Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1432 | break; | 
|  | 1433 | case Parameters::RECORD: | 
|  | 1434 | // Good to go for video snapshot | 
|  | 1435 | l.mParameters.state = Parameters::VIDEO_SNAPSHOT; | 
|  | 1436 | break; | 
|  | 1437 | case Parameters::STILL_CAPTURE: | 
|  | 1438 | case Parameters::VIDEO_SNAPSHOT: | 
|  | 1439 | ALOGE("%s: Camera %d: Already taking a picture", | 
|  | 1440 | __FUNCTION__, mCameraId); | 
|  | 1441 | return INVALID_OPERATION; | 
|  | 1442 | } | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1443 |  | 
| Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1444 | ALOGV("%s: Camera %d: Starting picture capture", __FUNCTION__, mCameraId); | 
| Zhijun He | e2d8375 | 2014-06-23 10:22:37 -0700 | [diff] [blame] | 1445 | int lastJpegStreamId = mJpegProcessor->getStreamId(); | 
| Yin-Chia Yeh | 355d9c6 | 2015-02-24 15:51:43 -0800 | [diff] [blame] | 1446 | // slowJpegMode will create jpeg stream in CaptureSequencer before capturing | 
|  | 1447 | if (!l.mParameters.slowJpegMode) { | 
|  | 1448 | res = updateProcessorStream(mJpegProcessor, l.mParameters); | 
|  | 1449 | } | 
|  | 1450 |  | 
| Yin-Chia Yeh | d3c5b08 | 2014-09-15 14:50:06 -0700 | [diff] [blame] | 1451 | // If video snapshot fail to configureStream, try override video snapshot size to | 
|  | 1452 | // video size | 
|  | 1453 | if (res == BAD_VALUE && l.mParameters.state == Parameters::VIDEO_SNAPSHOT) { | 
|  | 1454 | overrideVideoSnapshotSize(l.mParameters); | 
|  | 1455 | res = updateProcessorStream(mJpegProcessor, l.mParameters); | 
|  | 1456 | } | 
| Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1457 | if (res != OK) { | 
|  | 1458 | ALOGE("%s: Camera %d: Can't set up still image stream: %s (%d)", | 
|  | 1459 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1460 | return res; | 
|  | 1461 | } | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1462 | takePictureCounter = ++l.mParameters.takePictureCounter; | 
| Zhijun He | e2d8375 | 2014-06-23 10:22:37 -0700 | [diff] [blame] | 1463 |  | 
|  | 1464 | // Clear ZSL buffer queue when Jpeg size is changed. | 
|  | 1465 | bool jpegStreamChanged = mJpegProcessor->getStreamId() != lastJpegStreamId; | 
| Eino-Ville Talvala | c451d0f | 2016-06-30 17:17:35 -0700 | [diff] [blame] | 1466 | if (l.mParameters.allowZslMode && jpegStreamChanged) { | 
| Zhijun He | e2d8375 | 2014-06-23 10:22:37 -0700 | [diff] [blame] | 1467 | ALOGV("%s: Camera %d: Clear ZSL buffer queue when Jpeg size is changed", | 
|  | 1468 | __FUNCTION__, mCameraId); | 
|  | 1469 | mZslProcessor->clearZslQueue(); | 
|  | 1470 | } | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1471 | } | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1472 |  | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1473 | ATRACE_ASYNC_BEGIN(kTakepictureLabel, takePictureCounter); | 
|  | 1474 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1475 | // Need HAL to have correct settings before (possibly) triggering precapture | 
|  | 1476 | syncWithDevice(); | 
|  | 1477 |  | 
| Igor Murashkin | aa9e3e0 | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 1478 | res = mCaptureSequencer->startCapture(msgType); | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1479 | if (res != OK) { | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1480 | ALOGE("%s: Camera %d: Unable to start capture: %s (%d)", | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1481 | __FUNCTION__, mCameraId, strerror(-res), res); | 
| Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1482 | } | 
| Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1483 |  | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1484 | return res; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1485 | } | 
|  | 1486 |  | 
|  | 1487 | status_t Camera2Client::setParameters(const String8& params) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1488 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1489 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1490 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1491 | status_t res; | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1492 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
|  | 1493 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1494 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1495 |  | 
| Yin-Chia Yeh | dec84fb | 2014-09-10 15:14:18 -0700 | [diff] [blame] | 1496 | Parameters::focusMode_t focusModeBefore = l.mParameters.focusMode; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1497 | res = l.mParameters.set(params); | 
|  | 1498 | if (res != OK) return res; | 
| Yin-Chia Yeh | dec84fb | 2014-09-10 15:14:18 -0700 | [diff] [blame] | 1499 | Parameters::focusMode_t focusModeAfter = l.mParameters.focusMode; | 
|  | 1500 |  | 
| Eino-Ville Talvala | c451d0f | 2016-06-30 17:17:35 -0700 | [diff] [blame] | 1501 | if (l.mParameters.allowZslMode && focusModeAfter != focusModeBefore) { | 
| Yin-Chia Yeh | dec84fb | 2014-09-10 15:14:18 -0700 | [diff] [blame] | 1502 | mZslProcessor->clearZslQueue(); | 
|  | 1503 | } | 
| Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1504 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1505 | res = updateRequests(l.mParameters); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1506 |  | 
|  | 1507 | return res; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1508 | } | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 1509 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1510 | String8 Camera2Client::getParameters() const { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1511 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1512 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1513 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Igor Murashkin | ebe865b | 2014-08-07 17:07:28 -0700 | [diff] [blame] | 1514 | // The camera service can unconditionally get the parameters at all times | 
|  | 1515 | if (getCallingPid() != mServicePid && checkPid(__FUNCTION__) != OK) return String8(); | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1516 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1517 | SharedParameters::ReadLock l(mParameters); | 
| Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1518 |  | 
| Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1519 | return l.mParameters.get(); | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1520 | } | 
|  | 1521 |  | 
|  | 1522 | status_t Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) { | 
| Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1523 | ATRACE_CALL(); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1524 | Mutex::Autolock icl(mBinderSerializationLock); | 
| Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1525 | status_t res; | 
|  | 1526 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
| Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1527 |  | 
|  | 1528 | ALOGV("%s: Camera %d: Command %d (%d, %d)", __FUNCTION__, mCameraId, | 
|  | 1529 | cmd, arg1, arg2); | 
|  | 1530 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1531 | switch (cmd) { | 
|  | 1532 | case CAMERA_CMD_START_SMOOTH_ZOOM: | 
|  | 1533 | return commandStartSmoothZoomL(); | 
|  | 1534 | case CAMERA_CMD_STOP_SMOOTH_ZOOM: | 
|  | 1535 | return commandStopSmoothZoomL(); | 
|  | 1536 | case CAMERA_CMD_SET_DISPLAY_ORIENTATION: | 
|  | 1537 | return commandSetDisplayOrientationL(arg1); | 
|  | 1538 | case CAMERA_CMD_ENABLE_SHUTTER_SOUND: | 
|  | 1539 | return commandEnableShutterSoundL(arg1 == 1); | 
|  | 1540 | case CAMERA_CMD_PLAY_RECORDING_SOUND: | 
|  | 1541 | return commandPlayRecordingSoundL(); | 
|  | 1542 | case CAMERA_CMD_START_FACE_DETECTION: | 
|  | 1543 | return commandStartFaceDetectionL(arg1); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1544 | case CAMERA_CMD_STOP_FACE_DETECTION: { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1545 | SharedParameters::Lock l(mParameters); | 
|  | 1546 | return commandStopFaceDetectionL(l.mParameters); | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1547 | } | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1548 | case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG: | 
|  | 1549 | return commandEnableFocusMoveMsgL(arg1 == 1); | 
|  | 1550 | case CAMERA_CMD_PING: | 
|  | 1551 | return commandPingL(); | 
|  | 1552 | case CAMERA_CMD_SET_VIDEO_BUFFER_COUNT: | 
| Eino-Ville Talvala | d46a6b9 | 2015-05-14 17:26:24 -0700 | [diff] [blame] | 1553 | case CAMERA_CMD_SET_VIDEO_FORMAT: | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 1554 | ALOGE("%s: command %d (arguments %d, %d) is not supported.", | 
|  | 1555 | __FUNCTION__, cmd, arg1, arg2); | 
|  | 1556 | return BAD_VALUE; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1557 | default: | 
|  | 1558 | ALOGE("%s: Unknown command %d (arguments %d, %d)", | 
|  | 1559 | __FUNCTION__, cmd, arg1, arg2); | 
| Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1560 | return BAD_VALUE; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1561 | } | 
|  | 1562 | } | 
| James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1563 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1564 | status_t Camera2Client::commandStartSmoothZoomL() { | 
|  | 1565 | ALOGE("%s: Unimplemented!", __FUNCTION__); | 
|  | 1566 | return OK; | 
|  | 1567 | } | 
| James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1568 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1569 | status_t Camera2Client::commandStopSmoothZoomL() { | 
|  | 1570 | ALOGE("%s: Unimplemented!", __FUNCTION__); | 
|  | 1571 | return OK; | 
|  | 1572 | } | 
| James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1573 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1574 | status_t Camera2Client::commandSetDisplayOrientationL(int degrees) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1575 | int transform = Parameters::degToTransform(degrees, | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1576 | mCameraFacing == CAMERA_FACING_FRONT); | 
|  | 1577 | if (transform == -1) { | 
|  | 1578 | ALOGE("%s: Camera %d: Error setting %d as display orientation value", | 
|  | 1579 | __FUNCTION__, mCameraId, degrees); | 
|  | 1580 | return BAD_VALUE; | 
|  | 1581 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1582 | SharedParameters::Lock l(mParameters); | 
|  | 1583 | if (transform != l.mParameters.previewTransform && | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1584 | getPreviewStreamId() != NO_STREAM) { | 
|  | 1585 | mDevice->setStreamTransform(getPreviewStreamId(), transform); | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1586 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1587 | l.mParameters.previewTransform = transform; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1588 | return OK; | 
|  | 1589 | } | 
|  | 1590 |  | 
|  | 1591 | status_t Camera2Client::commandEnableShutterSoundL(bool enable) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1592 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1593 | if (enable) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1594 | l.mParameters.playShutterSound = true; | 
| James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1595 | return OK; | 
| Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1596 | } | 
|  | 1597 |  | 
| Igor Murashkin | a858ea0 | 2014-08-19 14:53:08 -0700 | [diff] [blame] | 1598 | // the camera2 api legacy mode can unconditionally disable the shutter sound | 
|  | 1599 | if (mLegacyMode) { | 
|  | 1600 | ALOGV("%s: Disable shutter sound in legacy mode", __FUNCTION__); | 
|  | 1601 | l.mParameters.playShutterSound = false; | 
|  | 1602 | return OK; | 
|  | 1603 | } | 
|  | 1604 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1605 | // Disabling shutter sound may not be allowed. In that case only | 
|  | 1606 | // allow the mediaserver process to disable the sound. | 
|  | 1607 | char value[PROPERTY_VALUE_MAX]; | 
|  | 1608 | property_get("ro.camera.sound.forced", value, "0"); | 
|  | 1609 | if (strncmp(value, "0", 2) != 0) { | 
|  | 1610 | // Disabling shutter sound is not allowed. Deny if the current | 
|  | 1611 | // process is not mediaserver. | 
|  | 1612 | if (getCallingPid() != getpid()) { | 
|  | 1613 | ALOGE("Failed to disable shutter sound. Permission denied (pid %d)", | 
|  | 1614 | getCallingPid()); | 
|  | 1615 | return PERMISSION_DENIED; | 
|  | 1616 | } | 
|  | 1617 | } | 
|  | 1618 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1619 | l.mParameters.playShutterSound = false; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1620 | return OK; | 
|  | 1621 | } | 
|  | 1622 |  | 
|  | 1623 | status_t Camera2Client::commandPlayRecordingSoundL() { | 
| Chien-Yu Chen | 82104eb | 2015-10-14 11:29:31 -0700 | [diff] [blame] | 1624 | mCameraService->playSound(CameraService::SOUND_RECORDING_START); | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1625 | return OK; | 
|  | 1626 | } | 
|  | 1627 |  | 
| Igor Murashkin | ddf3c50 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1628 | status_t Camera2Client::commandStartFaceDetectionL(int /*type*/) { | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1629 | ALOGV("%s: Camera %d: Starting face detection", | 
|  | 1630 | __FUNCTION__, mCameraId); | 
|  | 1631 | status_t res; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1632 | SharedParameters::Lock l(mParameters); | 
|  | 1633 | switch (l.mParameters.state) { | 
|  | 1634 | case Parameters::DISCONNECTED: | 
|  | 1635 | case Parameters::STOPPED: | 
|  | 1636 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: | 
|  | 1637 | case Parameters::STILL_CAPTURE: | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1638 | ALOGE("%s: Camera %d: Cannot start face detection without preview active", | 
|  | 1639 | __FUNCTION__, mCameraId); | 
|  | 1640 | return INVALID_OPERATION; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1641 | case Parameters::PREVIEW: | 
|  | 1642 | case Parameters::RECORD: | 
|  | 1643 | case Parameters::VIDEO_SNAPSHOT: | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1644 | // Good to go for starting face detect | 
|  | 1645 | break; | 
|  | 1646 | } | 
|  | 1647 | // Ignoring type | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1648 | if (l.mParameters.fastInfo.bestFaceDetectMode == | 
| Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 1649 | ANDROID_STATISTICS_FACE_DETECT_MODE_OFF) { | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1650 | ALOGE("%s: Camera %d: Face detection not supported", | 
|  | 1651 | __FUNCTION__, mCameraId); | 
| Ziv Hendel | caf3a9c | 2013-03-21 03:25:32 +0200 | [diff] [blame] | 1652 | return BAD_VALUE; | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1653 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1654 | if (l.mParameters.enableFaceDetect) return OK; | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1655 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1656 | l.mParameters.enableFaceDetect = true; | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1657 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1658 | res = updateRequests(l.mParameters); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1659 |  | 
|  | 1660 | return res; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1661 | } | 
|  | 1662 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1663 | status_t Camera2Client::commandStopFaceDetectionL(Parameters ¶ms) { | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1664 | status_t res = OK; | 
|  | 1665 | ALOGV("%s: Camera %d: Stopping face detection", | 
|  | 1666 | __FUNCTION__, mCameraId); | 
|  | 1667 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1668 | if (!params.enableFaceDetect) return OK; | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1669 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1670 | params.enableFaceDetect = false; | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1671 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1672 | if (params.state == Parameters::PREVIEW | 
|  | 1673 | || params.state == Parameters::RECORD | 
|  | 1674 | || params.state == Parameters::VIDEO_SNAPSHOT) { | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1675 | res = updateRequests(params); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1676 | } | 
|  | 1677 |  | 
|  | 1678 | return res; | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1679 | } | 
|  | 1680 |  | 
|  | 1681 | status_t Camera2Client::commandEnableFocusMoveMsgL(bool enable) { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1682 | SharedParameters::Lock l(mParameters); | 
|  | 1683 | l.mParameters.enableFocusMoveMessages = enable; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1684 |  | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1685 | return OK; | 
|  | 1686 | } | 
|  | 1687 |  | 
|  | 1688 | status_t Camera2Client::commandPingL() { | 
|  | 1689 | // Always ping back if access is proper and device is alive | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1690 | SharedParameters::Lock l(mParameters); | 
|  | 1691 | if (l.mParameters.state != Parameters::DISCONNECTED) { | 
| Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1692 | return OK; | 
|  | 1693 | } else { | 
|  | 1694 | return NO_INIT; | 
|  | 1695 | } | 
|  | 1696 | } | 
|  | 1697 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 1698 | void Camera2Client::notifyError(int32_t errorCode, | 
| Ruben Brunk | a485dfe | 2015-04-14 13:43:47 -0700 | [diff] [blame] | 1699 | const CaptureResultExtras& resultExtras) { | 
|  | 1700 | int32_t err = CAMERA_ERROR_UNKNOWN; | 
|  | 1701 | switch(errorCode) { | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 1702 | case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED: | 
| Ruben Brunk | a485dfe | 2015-04-14 13:43:47 -0700 | [diff] [blame] | 1703 | err = CAMERA_ERROR_RELEASED; | 
|  | 1704 | break; | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 1705 | case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE: | 
| Ruben Brunk | a485dfe | 2015-04-14 13:43:47 -0700 | [diff] [blame] | 1706 | err = CAMERA_ERROR_UNKNOWN; | 
|  | 1707 | break; | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 1708 | case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE: | 
| Ruben Brunk | a485dfe | 2015-04-14 13:43:47 -0700 | [diff] [blame] | 1709 | err = CAMERA_ERROR_SERVER_DIED; | 
|  | 1710 | break; | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 1711 | case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST: | 
|  | 1712 | case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT: | 
|  | 1713 | case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER: | 
| Ruben Brunk | a485dfe | 2015-04-14 13:43:47 -0700 | [diff] [blame] | 1714 | ALOGW("%s: Received recoverable error %d from HAL - ignoring, requestId %" PRId32, | 
|  | 1715 | __FUNCTION__, errorCode, resultExtras.requestId); | 
|  | 1716 | return; | 
|  | 1717 | default: | 
|  | 1718 | err = CAMERA_ERROR_UNKNOWN; | 
|  | 1719 | break; | 
|  | 1720 | } | 
|  | 1721 |  | 
|  | 1722 | ALOGE("%s: Error condition %d reported by HAL, requestId %" PRId32, __FUNCTION__, errorCode, | 
|  | 1723 | resultExtras.requestId); | 
|  | 1724 |  | 
|  | 1725 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); | 
|  | 1726 | if (l.mRemoteCallback != nullptr) { | 
|  | 1727 | l.mRemoteCallback->notifyCallback(CAMERA_MSG_ERROR, err, 0); | 
|  | 1728 | } | 
|  | 1729 | } | 
|  | 1730 |  | 
|  | 1731 |  | 
| Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1732 | /** Device-related methods */ | 
| Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1733 | void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { | 
|  | 1734 | ALOGV("%s: Autofocus state now %d, last trigger %d", | 
|  | 1735 | __FUNCTION__, newState, triggerId); | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1736 | bool sendCompletedMessage = false; | 
|  | 1737 | bool sendMovingMessage = false; | 
|  | 1738 |  | 
|  | 1739 | bool success = false; | 
|  | 1740 | bool afInMotion = false; | 
|  | 1741 | { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1742 | SharedParameters::Lock l(mParameters); | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1743 | // Trace end of AF state | 
|  | 1744 | char tmp[32]; | 
|  | 1745 | if (l.mParameters.afStateCounter > 0) { | 
|  | 1746 | camera_metadata_enum_snprint( | 
|  | 1747 | ANDROID_CONTROL_AF_STATE, l.mParameters.focusState, tmp, sizeof(tmp)); | 
|  | 1748 | ATRACE_ASYNC_END(tmp, l.mParameters.afStateCounter); | 
|  | 1749 | } | 
|  | 1750 |  | 
|  | 1751 | // Update state | 
| Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1752 | l.mParameters.focusState = newState; | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1753 | l.mParameters.afStateCounter++; | 
|  | 1754 |  | 
|  | 1755 | // Trace start of AF state | 
|  | 1756 |  | 
|  | 1757 | camera_metadata_enum_snprint( | 
|  | 1758 | ANDROID_CONTROL_AF_STATE, l.mParameters.focusState, tmp, sizeof(tmp)); | 
|  | 1759 | ATRACE_ASYNC_BEGIN(tmp, l.mParameters.afStateCounter); | 
|  | 1760 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1761 | switch (l.mParameters.focusMode) { | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1762 | case Parameters::FOCUS_MODE_AUTO: | 
|  | 1763 | case Parameters::FOCUS_MODE_MACRO: | 
|  | 1764 | // Don't send notifications upstream if they're not for the current AF | 
|  | 1765 | // trigger. For example, if cancel was called in between, or if we | 
|  | 1766 | // already sent a notification about this AF call. | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1767 | if (triggerId != l.mParameters.currentAfTriggerId) break; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1768 | switch (newState) { | 
|  | 1769 | case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED: | 
|  | 1770 | success = true; | 
|  | 1771 | // no break | 
|  | 1772 | case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: | 
|  | 1773 | sendCompletedMessage = true; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1774 | l.mParameters.currentAfTriggerId = -1; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1775 | break; | 
|  | 1776 | case ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN: | 
|  | 1777 | // Just starting focusing, ignore | 
|  | 1778 | break; | 
|  | 1779 | case ANDROID_CONTROL_AF_STATE_INACTIVE: | 
|  | 1780 | case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN: | 
|  | 1781 | case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED: | 
| Eino-Ville Talvala | 4ad28ea | 2013-09-20 17:21:18 -0700 | [diff] [blame] | 1782 | case ANDROID_CONTROL_AF_STATE_PASSIVE_UNFOCUSED: | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1783 | default: | 
|  | 1784 | // Unexpected in AUTO/MACRO mode | 
|  | 1785 | ALOGE("%s: Unexpected AF state transition in AUTO/MACRO mode: %d", | 
|  | 1786 | __FUNCTION__, newState); | 
|  | 1787 | break; | 
|  | 1788 | } | 
|  | 1789 | break; | 
|  | 1790 | case Parameters::FOCUS_MODE_CONTINUOUS_VIDEO: | 
|  | 1791 | case Parameters::FOCUS_MODE_CONTINUOUS_PICTURE: | 
|  | 1792 | switch (newState) { | 
|  | 1793 | case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED: | 
|  | 1794 | success = true; | 
|  | 1795 | // no break | 
|  | 1796 | case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: | 
|  | 1797 | // Don't send notifications upstream if they're not for | 
|  | 1798 | // the current AF trigger. For example, if cancel was | 
|  | 1799 | // called in between, or if we already sent a | 
|  | 1800 | // notification about this AF call. | 
|  | 1801 | // Send both a 'AF done' callback and a 'AF move' callback | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1802 | if (triggerId != l.mParameters.currentAfTriggerId) break; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1803 | sendCompletedMessage = true; | 
|  | 1804 | afInMotion = false; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1805 | if (l.mParameters.enableFocusMoveMessages && | 
|  | 1806 | l.mParameters.afInMotion) { | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1807 | sendMovingMessage = true; | 
|  | 1808 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1809 | l.mParameters.currentAfTriggerId = -1; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1810 | break; | 
|  | 1811 | case ANDROID_CONTROL_AF_STATE_INACTIVE: | 
|  | 1812 | // Cancel was called, or we switched state; care if | 
|  | 1813 | // currently moving | 
|  | 1814 | afInMotion = false; | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1815 | if (l.mParameters.enableFocusMoveMessages && | 
|  | 1816 | l.mParameters.afInMotion) { | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1817 | sendMovingMessage = true; | 
|  | 1818 | } | 
|  | 1819 | break; | 
|  | 1820 | case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN: | 
|  | 1821 | // Start passive scan, inform upstream | 
|  | 1822 | afInMotion = true; | 
|  | 1823 | // no break | 
|  | 1824 | case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED: | 
| Eino-Ville Talvala | 4ad28ea | 2013-09-20 17:21:18 -0700 | [diff] [blame] | 1825 | case ANDROID_CONTROL_AF_STATE_PASSIVE_UNFOCUSED: | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1826 | // Stop passive scan, inform upstream | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1827 | if (l.mParameters.enableFocusMoveMessages) { | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1828 | sendMovingMessage = true; | 
|  | 1829 | } | 
|  | 1830 | break; | 
|  | 1831 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1832 | l.mParameters.afInMotion = afInMotion; | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1833 | break; | 
|  | 1834 | case Parameters::FOCUS_MODE_EDOF: | 
|  | 1835 | case Parameters::FOCUS_MODE_INFINITY: | 
|  | 1836 | case Parameters::FOCUS_MODE_FIXED: | 
|  | 1837 | default: | 
|  | 1838 | if (newState != ANDROID_CONTROL_AF_STATE_INACTIVE) { | 
| Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1839 | ALOGE("%s: Unexpected AF state change %d " | 
|  | 1840 | "(ID %d) in focus mode %d", | 
|  | 1841 | __FUNCTION__, newState, triggerId, | 
|  | 1842 | l.mParameters.focusMode); | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1843 | } | 
|  | 1844 | } | 
|  | 1845 | } | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1846 | if (sendMovingMessage) { | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1847 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); | 
|  | 1848 | if (l.mRemoteCallback != 0) { | 
|  | 1849 | l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS_MOVE, | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1850 | afInMotion ? 1 : 0, 0); | 
|  | 1851 | } | 
| Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1852 | } | 
| Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 1853 | if (sendCompletedMessage) { | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 1854 | ATRACE_ASYNC_END(kAutofocusLabel, triggerId); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1855 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); | 
|  | 1856 | if (l.mRemoteCallback != 0) { | 
|  | 1857 | l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, | 
| Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1858 | success ? 1 : 0, 0); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1859 | } | 
| Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 1860 | } | 
| Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1861 | } | 
|  | 1862 |  | 
|  | 1863 | void Camera2Client::notifyAutoExposure(uint8_t newState, int triggerId) { | 
|  | 1864 | ALOGV("%s: Autoexposure state now %d, last trigger %d", | 
|  | 1865 | __FUNCTION__, newState, triggerId); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1866 | mCaptureSequencer->notifyAutoExposure(newState, triggerId); | 
| Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1867 | } | 
|  | 1868 |  | 
| Yin-Chia Yeh | 216db74 | 2015-05-18 15:03:35 -0700 | [diff] [blame] | 1869 | void Camera2Client::notifyShutter(const CaptureResultExtras& resultExtras, | 
|  | 1870 | nsecs_t timestamp) { | 
|  | 1871 | (void)resultExtras; | 
|  | 1872 | (void)timestamp; | 
|  | 1873 |  | 
|  | 1874 | ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64, | 
|  | 1875 | __FUNCTION__, resultExtras.requestId, timestamp); | 
|  | 1876 | mCaptureSequencer->notifyShutter(resultExtras, timestamp); | 
| Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 1877 |  | 
|  | 1878 | Camera2ClientBase::notifyShutter(resultExtras, timestamp); | 
| Yin-Chia Yeh | 216db74 | 2015-05-18 15:03:35 -0700 | [diff] [blame] | 1879 | } | 
|  | 1880 |  | 
| Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1881 | camera2::SharedParameters& Camera2Client::getParameters() { | 
|  | 1882 | return mParameters; | 
| Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1883 | } | 
|  | 1884 |  | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1885 | int Camera2Client::getPreviewStreamId() const { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1886 | return mStreamingProcessor->getPreviewStreamId(); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1887 | } | 
|  | 1888 |  | 
|  | 1889 | int Camera2Client::getCaptureStreamId() const { | 
|  | 1890 | return mJpegProcessor->getStreamId(); | 
|  | 1891 | } | 
|  | 1892 |  | 
|  | 1893 | int Camera2Client::getCallbackStreamId() const { | 
|  | 1894 | return mCallbackProcessor->getStreamId(); | 
|  | 1895 | } | 
|  | 1896 |  | 
|  | 1897 | int Camera2Client::getRecordingStreamId() const { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1898 | return mStreamingProcessor->getRecordingStreamId(); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1899 | } | 
|  | 1900 |  | 
|  | 1901 | int Camera2Client::getZslStreamId() const { | 
|  | 1902 | return mZslProcessor->getStreamId(); | 
|  | 1903 | } | 
|  | 1904 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1905 | status_t Camera2Client::registerFrameListener(int32_t minId, int32_t maxId, | 
| Chih-Hung Hsieh | 5404ee1 | 2016-08-09 14:25:53 -0700 | [diff] [blame] | 1906 | const wp<camera2::FrameProcessor::FilteredListener>& listener, bool sendPartials) { | 
| Zhijun He | 25a0aef | 2014-06-25 11:40:02 -0700 | [diff] [blame] | 1907 | return mFrameProcessor->registerListener(minId, maxId, listener, sendPartials); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1908 | } | 
|  | 1909 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1910 | status_t Camera2Client::removeFrameListener(int32_t minId, int32_t maxId, | 
| Chih-Hung Hsieh | 5404ee1 | 2016-08-09 14:25:53 -0700 | [diff] [blame] | 1911 | const wp<camera2::FrameProcessor::FilteredListener>& listener) { | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1912 | return mFrameProcessor->removeListener(minId, maxId, listener); | 
|  | 1913 | } | 
|  | 1914 |  | 
|  | 1915 | status_t Camera2Client::stopStream() { | 
|  | 1916 | return mStreamingProcessor->stopStream(); | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1917 | } | 
|  | 1918 |  | 
| Yin-Chia Yeh | 355d9c6 | 2015-02-24 15:51:43 -0800 | [diff] [blame] | 1919 | status_t Camera2Client::createJpegStreamL(Parameters ¶ms) { | 
|  | 1920 | status_t res = OK; | 
|  | 1921 | int lastJpegStreamId = mJpegProcessor->getStreamId(); | 
|  | 1922 | if (lastJpegStreamId != NO_STREAM) { | 
|  | 1923 | return INVALID_OPERATION; | 
|  | 1924 | } | 
|  | 1925 |  | 
|  | 1926 | res = mStreamingProcessor->togglePauseStream(/*pause*/true); | 
|  | 1927 | if (res != OK) { | 
|  | 1928 | ALOGE("%s: Camera %d: Can't pause streaming: %s (%d)", | 
|  | 1929 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1930 | return res; | 
|  | 1931 | } | 
|  | 1932 |  | 
|  | 1933 | res = mDevice->flush(); | 
|  | 1934 | if (res != OK) { | 
|  | 1935 | ALOGE("%s: Camera %d: Unable flush device: %s (%d)", | 
|  | 1936 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1937 | return res; | 
|  | 1938 | } | 
|  | 1939 |  | 
|  | 1940 | // Ideally we don't need this, but current camera device | 
|  | 1941 | // status tracking mechanism demands it. | 
|  | 1942 | res = mDevice->waitUntilDrained(); | 
|  | 1943 | if (res != OK) { | 
|  | 1944 | ALOGE("%s: Camera %d: Waiting device drain failed: %s (%d)", | 
|  | 1945 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1946 | } | 
|  | 1947 |  | 
|  | 1948 | res = updateProcessorStream(mJpegProcessor, params); | 
|  | 1949 | return res; | 
|  | 1950 | } | 
|  | 1951 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1952 | const int32_t Camera2Client::kPreviewRequestIdStart; | 
|  | 1953 | const int32_t Camera2Client::kPreviewRequestIdEnd; | 
|  | 1954 | const int32_t Camera2Client::kRecordingRequestIdStart; | 
|  | 1955 | const int32_t Camera2Client::kRecordingRequestIdEnd; | 
|  | 1956 | const int32_t Camera2Client::kCaptureRequestIdStart; | 
|  | 1957 | const int32_t Camera2Client::kCaptureRequestIdEnd; | 
| Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1958 |  | 
| Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1959 | /** Utility methods */ | 
|  | 1960 |  | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 1961 | status_t Camera2Client::updateRequests(Parameters ¶ms) { | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1962 | status_t res; | 
|  | 1963 |  | 
| Igor Murashkin | 22d58d3 | 2012-10-02 19:07:14 -0700 | [diff] [blame] | 1964 | ALOGV("%s: Camera %d: state = %d", __FUNCTION__, getCameraId(), params.state); | 
|  | 1965 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1966 | res = mStreamingProcessor->incrementStreamingIds(); | 
|  | 1967 | if (res != OK) { | 
|  | 1968 | ALOGE("%s: Camera %d: Unable to increment request IDs: %s (%d)", | 
|  | 1969 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1970 | return res; | 
|  | 1971 | } | 
|  | 1972 |  | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1973 | res = mStreamingProcessor->updatePreviewRequest(params); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1974 | if (res != OK) { | 
|  | 1975 | ALOGE("%s: Camera %d: Unable to update preview request: %s (%d)", | 
|  | 1976 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1977 | return res; | 
|  | 1978 | } | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1979 | res = mStreamingProcessor->updateRecordingRequest(params); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1980 | if (res != OK) { | 
|  | 1981 | ALOGE("%s: Camera %d: Unable to update recording request: %s (%d)", | 
|  | 1982 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1983 | return res; | 
|  | 1984 | } | 
|  | 1985 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1986 | if (params.state == Parameters::PREVIEW) { | 
| Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 1987 | res = startPreviewL(params, true); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1988 | if (res != OK) { | 
|  | 1989 | ALOGE("%s: Camera %d: Error streaming new preview request: %s (%d)", | 
|  | 1990 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1991 | return res; | 
|  | 1992 | } | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1993 | } else if (params.state == Parameters::RECORD || | 
|  | 1994 | params.state == Parameters::VIDEO_SNAPSHOT) { | 
| Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1995 | res = startRecordingL(params, true); | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1996 | if (res != OK) { | 
|  | 1997 | ALOGE("%s: Camera %d: Error streaming new record request: %s (%d)", | 
|  | 1998 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 1999 | return res; | 
|  | 2000 | } | 
|  | 2001 | } | 
|  | 2002 | return res; | 
|  | 2003 | } | 
|  | 2004 |  | 
| Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 2005 |  | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 2006 | size_t Camera2Client::calculateBufferSize(int width, int height, | 
|  | 2007 | int format, int stride) { | 
|  | 2008 | switch (format) { | 
|  | 2009 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: // NV16 | 
|  | 2010 | return width * height * 2; | 
|  | 2011 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: // NV21 | 
|  | 2012 | return width * height * 3 / 2; | 
|  | 2013 | case HAL_PIXEL_FORMAT_YCbCr_422_I: // YUY2 | 
|  | 2014 | return width * height * 2; | 
|  | 2015 | case HAL_PIXEL_FORMAT_YV12: {      // YV12 | 
|  | 2016 | size_t ySize = stride * height; | 
| Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2017 | size_t uvStride = (stride / 2 + 0xF) & ~0xF; | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 2018 | size_t uvSize = uvStride * height / 2; | 
|  | 2019 | return ySize + uvSize * 2; | 
|  | 2020 | } | 
|  | 2021 | case HAL_PIXEL_FORMAT_RGB_565: | 
|  | 2022 | return width * height * 2; | 
|  | 2023 | case HAL_PIXEL_FORMAT_RGBA_8888: | 
|  | 2024 | return width * height * 4; | 
| Eino-Ville Talvala | a97dfeb | 2015-02-19 16:26:13 -0800 | [diff] [blame] | 2025 | case HAL_PIXEL_FORMAT_RAW16: | 
| Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 2026 | return width * height * 2; | 
|  | 2027 | default: | 
|  | 2028 | ALOGE("%s: Unknown preview format: %x", | 
|  | 2029 | __FUNCTION__,  format); | 
|  | 2030 | return 0; | 
|  | 2031 | } | 
|  | 2032 | } | 
| Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 2033 |  | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 2034 | status_t Camera2Client::syncWithDevice() { | 
|  | 2035 | ATRACE_CALL(); | 
| Eino-Ville Talvala | 43b7ac6 | 2012-10-23 09:09:01 -0700 | [diff] [blame] | 2036 | const nsecs_t kMaxSyncTimeout = 500000000; // 500 ms | 
| Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 2037 | status_t res; | 
|  | 2038 |  | 
|  | 2039 | int32_t activeRequestId = mStreamingProcessor->getActiveRequestId(); | 
|  | 2040 | if (activeRequestId == 0) return OK; | 
|  | 2041 |  | 
|  | 2042 | res = mDevice->waitUntilRequestReceived(activeRequestId, kMaxSyncTimeout); | 
|  | 2043 | if (res == TIMED_OUT) { | 
|  | 2044 | ALOGE("%s: Camera %d: Timed out waiting sync with HAL", | 
|  | 2045 | __FUNCTION__, mCameraId); | 
|  | 2046 | } else if (res != OK) { | 
|  | 2047 | ALOGE("%s: Camera %d: Error while waiting to sync with HAL", | 
|  | 2048 | __FUNCTION__, mCameraId); | 
|  | 2049 | } | 
|  | 2050 | return res; | 
|  | 2051 | } | 
|  | 2052 |  | 
| Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 2053 | template <typename ProcessorT> | 
|  | 2054 | status_t Camera2Client::updateProcessorStream(sp<ProcessorT> processor, | 
|  | 2055 | camera2::Parameters params) { | 
| Igor Murashkin | 82db9e6 | 2013-05-21 11:38:49 -0700 | [diff] [blame] | 2056 | // No default template arguments until C++11, so we need this overload | 
|  | 2057 | return updateProcessorStream<ProcessorT, &ProcessorT::updateStream>( | 
|  | 2058 | processor, params); | 
|  | 2059 | } | 
|  | 2060 |  | 
|  | 2061 | template <typename ProcessorT, | 
|  | 2062 | status_t (ProcessorT::*updateStreamF)(const Parameters &)> | 
|  | 2063 | status_t Camera2Client::updateProcessorStream(sp<ProcessorT> processor, | 
|  | 2064 | Parameters params) { | 
| Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 2065 | status_t res; | 
|  | 2066 |  | 
| Igor Murashkin | 82db9e6 | 2013-05-21 11:38:49 -0700 | [diff] [blame] | 2067 | // Get raw pointer since sp<T> doesn't have operator->* | 
|  | 2068 | ProcessorT *processorPtr = processor.get(); | 
|  | 2069 | res = (processorPtr->*updateStreamF)(params); | 
| Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 2070 |  | 
|  | 2071 | /** | 
|  | 2072 | * Can't update the stream if it's busy? | 
|  | 2073 | * | 
|  | 2074 | * Then we need to stop the device (by temporarily clearing the request | 
|  | 2075 | * queue) and then try again. Resume streaming once we're done. | 
|  | 2076 | */ | 
|  | 2077 | if (res == -EBUSY) { | 
| Eino-Ville Talvala | a691ff3 | 2013-06-26 18:23:23 -0700 | [diff] [blame] | 2078 | ALOGV("%s: Camera %d: Pausing to update stream", __FUNCTION__, | 
|  | 2079 | mCameraId); | 
| Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 2080 | res = mStreamingProcessor->togglePauseStream(/*pause*/true); | 
|  | 2081 | if (res != OK) { | 
|  | 2082 | ALOGE("%s: Camera %d: Can't pause streaming: %s (%d)", | 
|  | 2083 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 2084 | } | 
|  | 2085 |  | 
|  | 2086 | res = mDevice->waitUntilDrained(); | 
|  | 2087 | if (res != OK) { | 
|  | 2088 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)", | 
|  | 2089 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 2090 | } | 
|  | 2091 |  | 
| Igor Murashkin | 82db9e6 | 2013-05-21 11:38:49 -0700 | [diff] [blame] | 2092 | res = (processorPtr->*updateStreamF)(params); | 
| Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 2093 | if (res != OK) { | 
|  | 2094 | ALOGE("%s: Camera %d: Failed to update processing stream " | 
|  | 2095 | " despite having halted streaming first: %s (%d)", | 
|  | 2096 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 2097 | } | 
|  | 2098 |  | 
|  | 2099 | res = mStreamingProcessor->togglePauseStream(/*pause*/false); | 
|  | 2100 | if (res != OK) { | 
|  | 2101 | ALOGE("%s: Camera %d: Can't unpause streaming: %s (%d)", | 
|  | 2102 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 2103 | } | 
|  | 2104 | } | 
|  | 2105 |  | 
|  | 2106 | return res; | 
|  | 2107 | } | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 2108 |  | 
| Yin-Chia Yeh | a53021f | 2014-09-12 14:50:27 -0700 | [diff] [blame] | 2109 | status_t Camera2Client::overrideVideoSnapshotSize(Parameters ¶ms) { | 
|  | 2110 | ALOGV("%s: Camera %d: configure still size to video size before recording" | 
|  | 2111 | , __FUNCTION__, mCameraId); | 
|  | 2112 | params.overrideJpegSizeByVideoSize(); | 
|  | 2113 | status_t res = updateProcessorStream(mJpegProcessor, params); | 
|  | 2114 | if (res != OK) { | 
|  | 2115 | ALOGE("%s: Camera %d: Can't override video snapshot size to video size: %s (%d)", | 
|  | 2116 | __FUNCTION__, mCameraId, strerror(-res), res); | 
|  | 2117 | } | 
|  | 2118 | return res; | 
|  | 2119 | } | 
|  | 2120 |  | 
| Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 2121 | status_t Camera2Client::setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer) { | 
|  | 2122 | ATRACE_CALL(); | 
|  | 2123 | ALOGV("%s: E", __FUNCTION__); | 
|  | 2124 | Mutex::Autolock icl(mBinderSerializationLock); | 
|  | 2125 | status_t res; | 
|  | 2126 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; | 
|  | 2127 |  | 
|  | 2128 | sp<IBinder> binder = IInterface::asBinder(bufferProducer); | 
|  | 2129 | if (binder == mVideoSurface) { | 
|  | 2130 | ALOGV("%s: Camera %d: New video window is same as old video window", | 
|  | 2131 | __FUNCTION__, mCameraId); | 
|  | 2132 | return NO_ERROR; | 
|  | 2133 | } | 
|  | 2134 |  | 
|  | 2135 | sp<Surface> window; | 
|  | 2136 | int format; | 
|  | 2137 | android_dataspace dataSpace; | 
|  | 2138 |  | 
|  | 2139 | if (bufferProducer != nullptr) { | 
|  | 2140 | // Using controlledByApp flag to ensure that the buffer queue remains in | 
|  | 2141 | // async mode for the old camera API, where many applications depend | 
|  | 2142 | // on that behavior. | 
|  | 2143 | window = new Surface(bufferProducer, /*controlledByApp*/ true); | 
|  | 2144 |  | 
|  | 2145 | ANativeWindow *anw = window.get(); | 
|  | 2146 |  | 
|  | 2147 | if ((res = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) { | 
|  | 2148 | ALOGE("%s: Failed to query Surface format", __FUNCTION__); | 
|  | 2149 | return res; | 
|  | 2150 | } | 
|  | 2151 |  | 
|  | 2152 | if ((res = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE, | 
|  | 2153 | reinterpret_cast<int*>(&dataSpace))) != OK) { | 
|  | 2154 | ALOGE("%s: Failed to query Surface dataSpace", __FUNCTION__); | 
|  | 2155 | return res; | 
|  | 2156 | } | 
|  | 2157 | } | 
|  | 2158 |  | 
|  | 2159 | Parameters::State state; | 
|  | 2160 | { | 
|  | 2161 | SharedParameters::Lock l(mParameters); | 
|  | 2162 | state = l.mParameters.state; | 
|  | 2163 | } | 
|  | 2164 |  | 
|  | 2165 | switch (state) { | 
|  | 2166 | case Parameters::STOPPED: | 
|  | 2167 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: | 
|  | 2168 | case Parameters::PREVIEW: | 
|  | 2169 | // OK | 
|  | 2170 | break; | 
|  | 2171 | case Parameters::DISCONNECTED: | 
|  | 2172 | case Parameters::RECORD: | 
|  | 2173 | case Parameters::STILL_CAPTURE: | 
|  | 2174 | case Parameters::VIDEO_SNAPSHOT: | 
|  | 2175 | default: | 
|  | 2176 | ALOGE("%s: Camera %d: Cannot set video target while in state %s", | 
|  | 2177 | __FUNCTION__, mCameraId, | 
|  | 2178 | Parameters::getStateName(state)); | 
|  | 2179 | return INVALID_OPERATION; | 
|  | 2180 | } | 
|  | 2181 |  | 
|  | 2182 | mVideoSurface = binder; | 
|  | 2183 | res = mStreamingProcessor->setRecordingWindow(window); | 
|  | 2184 | if (res != OK) { | 
|  | 2185 | ALOGE("%s: Unable to set new recording window: %s (%d)", | 
|  | 2186 | __FUNCTION__, strerror(-res), res); | 
|  | 2187 | return res; | 
|  | 2188 | } | 
|  | 2189 |  | 
|  | 2190 | { | 
|  | 2191 | SharedParameters::Lock l(mParameters); | 
|  | 2192 | l.mParameters.videoFormat = format; | 
|  | 2193 | l.mParameters.videoDataSpace = dataSpace; | 
|  | 2194 | } | 
|  | 2195 |  | 
|  | 2196 | return OK; | 
|  | 2197 | } | 
|  | 2198 |  | 
| Eino-Ville Talvala | 2b07e02 | 2013-10-10 15:13:09 -0700 | [diff] [blame] | 2199 | const char* Camera2Client::kAutofocusLabel = "autofocus"; | 
|  | 2200 | const char* Camera2Client::kTakepictureLabel = "take_picture"; | 
|  | 2201 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 2202 | } // namespace android |