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