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