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