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