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