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