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