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