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