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