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