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 | |
Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 17 | #define LOG_TAG "Camera2" |
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 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 21 | #include <utils/Log.h> |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 22 | #include <utils/Trace.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 23 | |
| 24 | #include <cutils/properties.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 25 | #include <gui/Surface.h> |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 26 | #include "camera2/Parameters.h" |
James Painter | 10894e5 | 2012-09-07 16:36:50 -0700 | [diff] [blame] | 27 | #include "Camera2Client.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 28 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 29 | #define ALOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); |
| 30 | #define ALOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); |
| 31 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 32 | namespace android { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 33 | using namespace camera2; |
| 34 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 35 | static int getCallingPid() { |
| 36 | return IPCThreadState::self()->getCallingPid(); |
| 37 | } |
| 38 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 39 | // Interface used by CameraService |
| 40 | |
| 41 | Camera2Client::Camera2Client(const sp<CameraService>& cameraService, |
| 42 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 43 | const String16& clientPackageName, |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 44 | int cameraId, |
| 45 | int cameraFacing, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 46 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 47 | uid_t clientUid, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 48 | int servicePid): |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 49 | Client(cameraService, cameraClient, clientPackageName, |
| 50 | cameraId, cameraFacing, clientPid, clientUid, servicePid), |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 51 | mSharedCameraClient(cameraClient), |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 52 | mParameters(cameraId, cameraFacing) |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 53 | { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 54 | ATRACE_CALL(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 55 | ALOGI("Camera %d: Opened", cameraId); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 56 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 57 | mDevice = new Camera2Device(cameraId); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 58 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 59 | SharedParameters::Lock l(mParameters); |
| 60 | l.mParameters.state = Parameters::DISCONNECTED; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 63 | status_t Camera2Client::checkPid(const char* checkLocation) const { |
| 64 | int callingPid = getCallingPid(); |
Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 65 | if (callingPid == mClientPid) return NO_ERROR; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 66 | |
| 67 | ALOGE("%s: attempt to use a locked camera from a different process" |
Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 68 | " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 69 | return PERMISSION_DENIED; |
| 70 | } |
| 71 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 72 | status_t Camera2Client::initialize(camera_module_t *module) |
| 73 | { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 74 | ATRACE_CALL(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 75 | ALOGV("%s: Initializing client for camera %d", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 76 | status_t res; |
| 77 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 78 | // Verify ops permissions |
| 79 | res = startCameraOps(); |
| 80 | if (res != OK) { |
| 81 | return res; |
| 82 | } |
| 83 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 84 | res = mDevice->initialize(module); |
| 85 | if (res != OK) { |
| 86 | ALOGE("%s: Camera %d: unable to initialize device: %s (%d)", |
| 87 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 88 | return NO_INIT; |
| 89 | } |
| 90 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 91 | res = mDevice->setNotifyCallback(this); |
| 92 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 93 | SharedParameters::Lock l(mParameters); |
| 94 | |
| 95 | res = l.mParameters.initialize(&(mDevice->info())); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 96 | if (res != OK) { |
| 97 | ALOGE("%s: Camera %d: unable to build defaults: %s (%d)", |
| 98 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 99 | return NO_INIT; |
| 100 | } |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 101 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 102 | String8 threadName; |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 103 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 104 | mStreamingProcessor = new StreamingProcessor(this); |
| 105 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 106 | mFrameProcessor = new FrameProcessor(this); |
Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 107 | threadName = String8::format("C2-%d-FrameProc", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 108 | mCameraId); |
| 109 | mFrameProcessor->run(threadName.string()); |
| 110 | |
| 111 | mCaptureSequencer = new CaptureSequencer(this); |
Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 112 | threadName = String8::format("C2-%d-CaptureSeq", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 113 | mCameraId); |
| 114 | mCaptureSequencer->run(threadName.string()); |
| 115 | |
| 116 | mJpegProcessor = new JpegProcessor(this, mCaptureSequencer); |
Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 117 | threadName = String8::format("C2-%d-JpegProc", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 118 | mCameraId); |
| 119 | mJpegProcessor->run(threadName.string()); |
| 120 | |
| 121 | mZslProcessor = new ZslProcessor(this, mCaptureSequencer); |
Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 122 | threadName = String8::format("C2-%d-ZslProc", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 123 | mCameraId); |
| 124 | mZslProcessor->run(threadName.string()); |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 125 | |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 126 | mCallbackProcessor = new CallbackProcessor(this); |
Eino-Ville Talvala | 4bb8118 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 127 | threadName = String8::format("C2-%d-CallbkProc", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 128 | mCameraId); |
| 129 | mCallbackProcessor->run(threadName.string()); |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 130 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 131 | if (gLogLevel >= 1) { |
| 132 | ALOGD("%s: Default parameters converted from camera %d:", __FUNCTION__, |
| 133 | mCameraId); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 134 | ALOGD("%s", l.mParameters.paramsFlattened.string()); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 137 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | Camera2Client::~Camera2Client() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 141 | ATRACE_CALL(); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 142 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 143 | mDestructionStarted = true; |
| 144 | |
Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 145 | disconnect(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 146 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 147 | ALOGI("Camera %d: Closed", mCameraId); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | status_t Camera2Client::dump(int fd, const Vector<String16>& args) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 151 | String8 result; |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 152 | result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n", |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 153 | mCameraId, |
| 154 | getCameraClient()->asBinder().get(), |
| 155 | mClientPid); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 156 | result.append(" State: "); |
| 157 | #define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break; |
| 158 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 159 | const Parameters& p = mParameters.unsafeAccess(); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 160 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 161 | result.append(Parameters::getStateName(p.state)); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 162 | |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 163 | result.append("\n Current parameters:\n"); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 164 | result.appendFormat(" Preview size: %d x %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 165 | p.previewWidth, p.previewHeight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 166 | result.appendFormat(" Preview FPS range: %d - %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 167 | p.previewFpsRange[0], p.previewFpsRange[1]); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 168 | result.appendFormat(" Preview HAL pixel format: 0x%x\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 169 | p.previewFormat); |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 170 | result.appendFormat(" Preview transform: %x\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 171 | p.previewTransform); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 172 | result.appendFormat(" Picture size: %d x %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 173 | p.pictureWidth, p.pictureHeight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 174 | result.appendFormat(" Jpeg thumbnail size: %d x %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 175 | p.jpegThumbSize[0], p.jpegThumbSize[1]); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 176 | result.appendFormat(" Jpeg quality: %d, thumbnail quality: %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 177 | p.jpegQuality, p.jpegThumbQuality); |
| 178 | result.appendFormat(" Jpeg rotation: %d\n", p.jpegRotation); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 179 | result.appendFormat(" GPS tags %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 180 | p.gpsEnabled ? "enabled" : "disabled"); |
| 181 | if (p.gpsEnabled) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 182 | result.appendFormat(" GPS lat x long x alt: %f x %f x %f\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 183 | p.gpsCoordinates[0], p.gpsCoordinates[1], |
| 184 | p.gpsCoordinates[2]); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 185 | result.appendFormat(" GPS timestamp: %lld\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 186 | p.gpsTimestamp); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 187 | result.appendFormat(" GPS processing method: %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 188 | p.gpsProcessingMethod.string()); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | result.append(" White balance mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 192 | switch (p.wbMode) { |
Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 193 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_AUTO) |
| 194 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_INCANDESCENT) |
| 195 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_FLUORESCENT) |
| 196 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_WARM_FLUORESCENT) |
| 197 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_DAYLIGHT) |
| 198 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT) |
| 199 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_TWILIGHT) |
| 200 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_SHADE) |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 201 | default: result.append("UNKNOWN\n"); |
| 202 | } |
| 203 | |
| 204 | result.append(" Effect mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 205 | switch (p.effectMode) { |
Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 206 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_OFF) |
| 207 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_MONO) |
| 208 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_NEGATIVE) |
| 209 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_SOLARIZE) |
| 210 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_SEPIA) |
| 211 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_POSTERIZE) |
| 212 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_WHITEBOARD) |
| 213 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_BLACKBOARD) |
| 214 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_AQUA) |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 215 | default: result.append("UNKNOWN\n"); |
| 216 | } |
| 217 | |
| 218 | result.append(" Antibanding mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 219 | switch (p.antibandingMode) { |
Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 220 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO) |
| 221 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF) |
| 222 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ) |
| 223 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ) |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 224 | default: result.append("UNKNOWN\n"); |
| 225 | } |
| 226 | |
| 227 | result.append(" Scene mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 228 | switch (p.sceneMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 229 | case ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED: |
| 230 | result.append("AUTO\n"); break; |
| 231 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_ACTION) |
| 232 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PORTRAIT) |
| 233 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_LANDSCAPE) |
| 234 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT) |
| 235 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT) |
| 236 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_THEATRE) |
| 237 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BEACH) |
| 238 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SNOW) |
| 239 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SUNSET) |
| 240 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO) |
| 241 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_FIREWORKS) |
| 242 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SPORTS) |
| 243 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PARTY) |
| 244 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT) |
| 245 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BARCODE) |
| 246 | default: result.append("UNKNOWN\n"); |
| 247 | } |
| 248 | |
| 249 | result.append(" Flash mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 250 | switch (p.flashMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 251 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_OFF) |
| 252 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_AUTO) |
| 253 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_ON) |
| 254 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_TORCH) |
| 255 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_RED_EYE) |
| 256 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_INVALID) |
| 257 | default: result.append("UNKNOWN\n"); |
| 258 | } |
| 259 | |
| 260 | result.append(" Focus mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 261 | switch (p.focusMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 262 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_AUTO) |
| 263 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_MACRO) |
| 264 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_VIDEO) |
| 265 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_PICTURE) |
| 266 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_EDOF) |
| 267 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INFINITY) |
| 268 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_FIXED) |
| 269 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INVALID) |
| 270 | default: result.append("UNKNOWN\n"); |
| 271 | } |
| 272 | |
Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 273 | result.append(" Focus state: "); |
| 274 | switch (p.focusState) { |
| 275 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_INACTIVE) |
| 276 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN) |
| 277 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED) |
| 278 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN) |
| 279 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED) |
| 280 | CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) |
| 281 | default: result.append("UNKNOWN\n"); |
| 282 | } |
| 283 | |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 284 | result.append(" Focusing areas:\n"); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 285 | for (size_t i = 0; i < p.focusingAreas.size(); i++) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 286 | result.appendFormat(" [ (%d, %d, %d, %d), weight %d ]\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 287 | p.focusingAreas[i].left, |
| 288 | p.focusingAreas[i].top, |
| 289 | p.focusingAreas[i].right, |
| 290 | p.focusingAreas[i].bottom, |
| 291 | p.focusingAreas[i].weight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | result.appendFormat(" Exposure compensation index: %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 295 | p.exposureCompensation); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 296 | |
| 297 | result.appendFormat(" AE lock %s, AWB lock %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 298 | p.autoExposureLock ? "enabled" : "disabled", |
| 299 | p.autoWhiteBalanceLock ? "enabled" : "disabled" ); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 300 | |
| 301 | result.appendFormat(" Metering areas:\n"); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 302 | for (size_t i = 0; i < p.meteringAreas.size(); i++) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 303 | result.appendFormat(" [ (%d, %d, %d, %d), weight %d ]\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 304 | p.meteringAreas[i].left, |
| 305 | p.meteringAreas[i].top, |
| 306 | p.meteringAreas[i].right, |
| 307 | p.meteringAreas[i].bottom, |
| 308 | p.meteringAreas[i].weight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 311 | result.appendFormat(" Zoom index: %d\n", p.zoom); |
| 312 | result.appendFormat(" Video size: %d x %d\n", p.videoWidth, |
| 313 | p.videoHeight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 314 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 315 | result.appendFormat(" Recording hint is %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 316 | p.recordingHint ? "set" : "not set"); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 317 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 318 | result.appendFormat(" Video stabilization is %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 319 | p.videoStabilization ? "enabled" : "disabled"); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 320 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 321 | result.append(" Current streams:\n"); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 322 | result.appendFormat(" Preview stream ID: %d\n", |
| 323 | getPreviewStreamId()); |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 324 | result.appendFormat(" Capture stream ID: %d\n", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 325 | getCaptureStreamId()); |
| 326 | result.appendFormat(" Recording stream ID: %d\n", |
| 327 | getRecordingStreamId()); |
Eino-Ville Talvala | e382ee2 | 2012-10-02 18:14:49 -0700 | [diff] [blame] | 328 | |
| 329 | result.append(" Quirks for this camera:\n"); |
| 330 | bool haveQuirk = false; |
| 331 | if (p.quirks.triggerAfWithAuto) { |
| 332 | result.appendFormat(" triggerAfWithAuto\n"); |
| 333 | haveQuirk = true; |
| 334 | } |
| 335 | if (p.quirks.useZslFormat) { |
| 336 | result.appendFormat(" useZslFormat\n"); |
| 337 | haveQuirk = true; |
| 338 | } |
Igor Murashkin | 7373cbe | 2012-09-28 15:30:03 -0700 | [diff] [blame] | 339 | if (p.quirks.meteringCropRegion) { |
| 340 | result.appendFormat(" meteringCropRegion\n"); |
| 341 | haveQuirk = true; |
| 342 | } |
Eino-Ville Talvala | e382ee2 | 2012-10-02 18:14:49 -0700 | [diff] [blame] | 343 | if (!haveQuirk) { |
| 344 | result.appendFormat(" none\n"); |
| 345 | } |
| 346 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 347 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 348 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 349 | mStreamingProcessor->dump(fd, args); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 350 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 351 | mCaptureSequencer->dump(fd, args); |
| 352 | |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 353 | mFrameProcessor->dump(fd, args); |
| 354 | |
Eino-Ville Talvala | 97b38a8 | 2012-09-17 17:55:07 -0700 | [diff] [blame] | 355 | mZslProcessor->dump(fd, args); |
| 356 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 357 | result = " Device dump:\n"; |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 358 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 359 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 360 | status_t res = mDevice->dump(fd, args); |
| 361 | if (res != OK) { |
| 362 | result = String8::format(" Error dumping device: %s (%d)", |
| 363 | strerror(-res), res); |
| 364 | write(fd, result.string(), result.size()); |
| 365 | } |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 366 | |
| 367 | #undef CASE_APPEND_ENUM |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 368 | return NO_ERROR; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | // ICamera interface |
| 372 | |
| 373 | void Camera2Client::disconnect() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 374 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 375 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 376 | |
| 377 | // Allow both client and the media server to disconnect at all times |
| 378 | int callingPid = getCallingPid(); |
| 379 | if (callingPid != mClientPid && callingPid != mServicePid) return; |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 380 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 381 | if (mDevice == 0) return; |
| 382 | |
Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 383 | ALOGV("Camera %d: Shutting down", mCameraId); |
| 384 | |
Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 385 | stopPreviewL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 386 | |
Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 387 | { |
| 388 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | c037920 | 2012-10-09 22:16:58 -0700 | [diff] [blame] | 389 | if (l.mParameters.state == Parameters::DISCONNECTED) return; |
Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 390 | l.mParameters.state = Parameters::DISCONNECTED; |
| 391 | } |
| 392 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 393 | mStreamingProcessor->deletePreviewStream(); |
| 394 | mStreamingProcessor->deleteRecordingStream(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 395 | mJpegProcessor->deleteStream(); |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 396 | mCallbackProcessor->deleteStream(); |
Eino-Ville Talvala | cf70d34 | 2012-09-05 19:02:43 -0700 | [diff] [blame] | 397 | mZslProcessor->deleteStream(); |
| 398 | |
Eino-Ville Talvala | 98bb82d | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 399 | mFrameProcessor->requestExit(); |
| 400 | mCaptureSequencer->requestExit(); |
| 401 | mJpegProcessor->requestExit(); |
| 402 | mZslProcessor->requestExit(); |
| 403 | mCallbackProcessor->requestExit(); |
| 404 | |
| 405 | ALOGV("Camera %d: Waiting for threads", mCameraId); |
| 406 | |
| 407 | mFrameProcessor->join(); |
| 408 | mCaptureSequencer->join(); |
| 409 | mJpegProcessor->join(); |
| 410 | mZslProcessor->join(); |
| 411 | mCallbackProcessor->join(); |
| 412 | |
| 413 | ALOGV("Camera %d: Disconnecting device", mCameraId); |
| 414 | |
| 415 | mDevice->disconnect(); |
| 416 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 417 | mDevice.clear(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 418 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 419 | CameraService::Client::disconnect(); |
| 420 | } |
| 421 | |
| 422 | status_t Camera2Client::connect(const sp<ICameraClient>& client) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 423 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 424 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 425 | Mutex::Autolock icl(mICameraLock); |
| 426 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 427 | if (mClientPid != 0 && getCallingPid() != mClientPid) { |
| 428 | ALOGE("%s: Camera %d: Connection attempt from pid %d; " |
| 429 | "current locked to pid %d", __FUNCTION__, |
| 430 | mCameraId, getCallingPid(), mClientPid); |
| 431 | return BAD_VALUE; |
| 432 | } |
| 433 | |
| 434 | mClientPid = getCallingPid(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 435 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 436 | mCameraClient = client; |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 437 | mSharedCameraClient = client; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 438 | |
| 439 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | status_t Camera2Client::lock() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 443 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 444 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 445 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 446 | ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d", |
| 447 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 448 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 449 | if (mClientPid == 0) { |
| 450 | mClientPid = getCallingPid(); |
| 451 | return OK; |
| 452 | } |
| 453 | |
| 454 | if (mClientPid != getCallingPid()) { |
| 455 | ALOGE("%s: Camera %d: Lock call from pid %d; currently locked to pid %d", |
| 456 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
| 457 | return EBUSY; |
| 458 | } |
| 459 | |
| 460 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | status_t Camera2Client::unlock() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 464 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 465 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 466 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 467 | ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d", |
| 468 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 469 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 470 | if (mClientPid == getCallingPid()) { |
Eino-Ville Talvala | 907e565 | 2012-10-10 15:28:53 -0700 | [diff] [blame] | 471 | SharedParameters::Lock l(mParameters); |
| 472 | if (l.mParameters.state == Parameters::RECORD || |
| 473 | l.mParameters.state == Parameters::VIDEO_SNAPSHOT) { |
| 474 | ALOGD("Not allowed to unlock camera during recording."); |
| 475 | return INVALID_OPERATION; |
| 476 | } |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 477 | mClientPid = 0; |
| 478 | mCameraClient.clear(); |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 479 | mSharedCameraClient.clear(); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 480 | return OK; |
| 481 | } |
| 482 | |
| 483 | ALOGE("%s: Camera %d: Unlock call from pid %d; currently locked to pid %d", |
| 484 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
| 485 | return EBUSY; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 488 | status_t Camera2Client::setPreviewDisplay( |
| 489 | const sp<Surface>& surface) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 490 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 491 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 492 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 493 | status_t res; |
| 494 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 495 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 496 | sp<IBinder> binder; |
| 497 | sp<ANativeWindow> window; |
| 498 | if (surface != 0) { |
Mathias Agopian | 9e1cdea | 2013-02-19 18:25:33 -0800 | [diff] [blame] | 499 | binder = surface->getIGraphicBufferProducer()->asBinder(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 500 | window = surface; |
| 501 | } |
| 502 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 503 | return setPreviewWindowL(binder,window); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 506 | status_t Camera2Client::setPreviewTexture( |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 507 | const sp<IGraphicBufferProducer>& bufferProducer) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 508 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 509 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 510 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 511 | status_t res; |
| 512 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 513 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 514 | sp<IBinder> binder; |
| 515 | sp<ANativeWindow> window; |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 516 | if (bufferProducer != 0) { |
| 517 | binder = bufferProducer->asBinder(); |
Mathias Agopian | 1a2952a | 2013-02-14 17:11:27 -0800 | [diff] [blame] | 518 | window = new Surface(bufferProducer); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 519 | } |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 520 | return setPreviewWindowL(binder, window); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 523 | status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 524 | sp<ANativeWindow> window) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 525 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 526 | status_t res; |
| 527 | |
| 528 | if (binder == mPreviewSurface) { |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 529 | ALOGV("%s: Camera %d: New window is same as old window", |
| 530 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 531 | return NO_ERROR; |
| 532 | } |
| 533 | |
Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 534 | Parameters::State state; |
| 535 | { |
| 536 | SharedParameters::Lock l(mParameters); |
| 537 | state = l.mParameters.state; |
| 538 | } |
| 539 | switch (state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 540 | case Parameters::DISCONNECTED: |
| 541 | case Parameters::RECORD: |
| 542 | case Parameters::STILL_CAPTURE: |
| 543 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 544 | 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] | 545 | __FUNCTION__, mCameraId, |
Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 546 | Parameters::getStateName(state)); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 547 | return INVALID_OPERATION; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 548 | case Parameters::STOPPED: |
| 549 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 550 | // OK |
| 551 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 552 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 553 | // Already running preview - need to stop and create a new stream |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 554 | mStreamingProcessor->stopStream(); |
Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 555 | state = Parameters::WAITING_FOR_PREVIEW_WINDOW; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 556 | break; |
| 557 | } |
| 558 | |
Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 559 | mPreviewSurface = binder; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 560 | res = mStreamingProcessor->setPreviewWindow(window); |
| 561 | if (res != OK) { |
| 562 | ALOGE("%s: Unable to set new preview window: %s (%d)", |
| 563 | __FUNCTION__, strerror(-res), res); |
| 564 | return res; |
| 565 | } |
Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 566 | |
Eino-Ville Talvala | f1945f0 | 2012-10-17 16:32:34 -0700 | [diff] [blame] | 567 | if (state == Parameters::WAITING_FOR_PREVIEW_WINDOW) { |
| 568 | SharedParameters::Lock l(mParameters); |
| 569 | l.mParameters.state = state; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 570 | return startPreviewL(l.mParameters, false); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 573 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | void Camera2Client::setPreviewCallbackFlag(int flag) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 577 | ATRACE_CALL(); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 578 | ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 579 | Mutex::Autolock icl(mICameraLock); |
Igor Murashkin | ddf3c50 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 580 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 581 | if ( checkPid(__FUNCTION__) != OK) return; |
| 582 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 583 | SharedParameters::Lock l(mParameters); |
| 584 | setPreviewCallbackFlagL(l.mParameters, flag); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | void Camera2Client::setPreviewCallbackFlagL(Parameters ¶ms, int flag) { |
| 588 | status_t res = OK; |
| 589 | if (flag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) { |
| 590 | ALOGV("%s: setting oneshot", __FUNCTION__); |
| 591 | params.previewCallbackOneShot = true; |
| 592 | } |
| 593 | if (params.previewCallbackFlags != (uint32_t)flag) { |
| 594 | params.previewCallbackFlags = flag; |
| 595 | switch(params.state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 596 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 597 | res = startPreviewL(params, true); |
| 598 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 599 | case Parameters::RECORD: |
| 600 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 601 | res = startRecordingL(params, true); |
| 602 | break; |
| 603 | default: |
| 604 | break; |
| 605 | } |
| 606 | if (res != OK) { |
| 607 | ALOGE("%s: Camera %d: Unable to refresh request in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 608 | __FUNCTION__, mCameraId, |
| 609 | Parameters::getStateName(params.state)); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | status_t Camera2Client::startPreview() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 616 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 617 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 618 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 619 | status_t res; |
| 620 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 621 | SharedParameters::Lock l(mParameters); |
| 622 | return startPreviewL(l.mParameters, false); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 623 | } |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 624 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 625 | status_t Camera2Client::startPreviewL(Parameters ¶ms, bool restart) { |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 626 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 627 | status_t res; |
Igor Murashkin | 22d58d3 | 2012-10-02 19:07:14 -0700 | [diff] [blame] | 628 | |
| 629 | ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart); |
| 630 | |
Eino-Ville Talvala | a14be59 | 2012-10-10 17:17:01 -0700 | [diff] [blame] | 631 | if ( (params.state == Parameters::PREVIEW || |
| 632 | params.state == Parameters::RECORD || |
| 633 | params.state == Parameters::VIDEO_SNAPSHOT) |
| 634 | && !restart) { |
| 635 | // Succeed attempt to re-enter a streaming state |
| 636 | ALOGI("%s: Camera %d: Preview already active, ignoring restart", |
| 637 | __FUNCTION__, mCameraId); |
Alex Ray | 77449ad | 2012-09-26 15:52:50 -0700 | [diff] [blame] | 638 | return OK; |
| 639 | } |
| 640 | if (params.state > Parameters::PREVIEW && !restart) { |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 641 | ALOGE("%s: Can't start preview in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 642 | __FUNCTION__, |
| 643 | Parameters::getStateName(params.state)); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 644 | return INVALID_OPERATION; |
| 645 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 646 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 647 | if (!mStreamingProcessor->haveValidPreviewWindow()) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 648 | params.state = Parameters::WAITING_FOR_PREVIEW_WINDOW; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 649 | return OK; |
| 650 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 651 | params.state = Parameters::STOPPED; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 652 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 653 | res = mStreamingProcessor->updatePreviewStream(params); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 654 | if (res != OK) { |
| 655 | ALOGE("%s: Camera %d: Unable to update preview stream: %s (%d)", |
| 656 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 657 | return res; |
| 658 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 659 | |
| 660 | Vector<uint8_t> outputStreams; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 661 | bool callbacksEnabled = params.previewCallbackFlags & |
| 662 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK; |
| 663 | if (callbacksEnabled) { |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 664 | res = mCallbackProcessor->updateStream(params); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 665 | if (res != OK) { |
| 666 | ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)", |
| 667 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 668 | return res; |
| 669 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 670 | outputStreams.push(getCallbackStreamId()); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 671 | } |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 672 | if (params.zslMode && !params.recordingHint) { |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 673 | res = mZslProcessor->updateStream(params); |
| 674 | if (res != OK) { |
| 675 | ALOGE("%s: Camera %d: Unable to update ZSL stream: %s (%d)", |
| 676 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 677 | return res; |
| 678 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 679 | outputStreams.push(getZslStreamId()); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 680 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 681 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 682 | outputStreams.push(getPreviewStreamId()); |
| 683 | |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 684 | if (!params.recordingHint) { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 685 | if (!restart) { |
| 686 | res = mStreamingProcessor->updatePreviewRequest(params); |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 687 | if (res != OK) { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 688 | ALOGE("%s: Camera %d: Can't set up preview request: " |
| 689 | "%s (%d)", __FUNCTION__, mCameraId, |
| 690 | strerror(-res), res); |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 691 | return res; |
| 692 | } |
| 693 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 694 | res = mStreamingProcessor->startStream(StreamingProcessor::PREVIEW, |
| 695 | outputStreams); |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 696 | } else { |
| 697 | // With recording hint set, we're going to be operating under the |
| 698 | // assumption that the user will record video. To optimize recording |
| 699 | // startup time, create the necessary output streams for recording and |
| 700 | // video snapshot now if they don't already exist. |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 701 | res = mJpegProcessor->updateStream(params); |
| 702 | if (res != OK) { |
| 703 | ALOGE("%s: Camera %d: Can't pre-configure still image " |
| 704 | "stream: %s (%d)", |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 705 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 706 | return res; |
| 707 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 708 | |
| 709 | if (!restart) { |
| 710 | res = mStreamingProcessor->updateRecordingRequest(params); |
| 711 | if (res != OK) { |
| 712 | ALOGE("%s: Camera %d: Can't set up preview request with " |
| 713 | "record hint: %s (%d)", __FUNCTION__, mCameraId, |
| 714 | strerror(-res), res); |
| 715 | return res; |
| 716 | } |
| 717 | } |
| 718 | res = mStreamingProcessor->startStream(StreamingProcessor::RECORD, |
| 719 | outputStreams); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 720 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 721 | if (res != OK) { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 722 | ALOGE("%s: Camera %d: Unable to start streaming preview: %s (%d)", |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 723 | __FUNCTION__, mCameraId, strerror(-res), res); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 724 | return res; |
| 725 | } |
| 726 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 727 | params.state = Parameters::PREVIEW; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 728 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void Camera2Client::stopPreview() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 732 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 733 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 734 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 735 | status_t res; |
| 736 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 737 | stopPreviewL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 740 | void Camera2Client::stopPreviewL() { |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 741 | ATRACE_CALL(); |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 742 | status_t res; |
Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 743 | const nsecs_t kStopCaptureTimeout = 3000000000LL; // 3 seconds |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 744 | Parameters::State state; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 745 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 746 | SharedParameters::Lock l(mParameters); |
| 747 | state = l.mParameters.state; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | switch (state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 751 | case Parameters::DISCONNECTED: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 752 | // Nothing to do. |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 753 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 754 | case Parameters::STOPPED: |
Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 755 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 756 | case Parameters::STILL_CAPTURE: |
Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 757 | mCaptureSequencer->waitUntilIdle(kStopCaptureTimeout); |
| 758 | // no break |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 759 | case Parameters::RECORD: |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 760 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 761 | mStreamingProcessor->stopStream(); |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 762 | res = mDevice->waitUntilDrained(); |
| 763 | if (res != OK) { |
| 764 | ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)", |
| 765 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 766 | } |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 767 | // no break |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 768 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: { |
| 769 | SharedParameters::Lock l(mParameters); |
| 770 | l.mParameters.state = Parameters::STOPPED; |
| 771 | commandStopFaceDetectionL(l.mParameters); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 772 | break; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 773 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 774 | default: |
| 775 | ALOGE("%s: Camera %d: Unknown state %d", __FUNCTION__, mCameraId, |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 776 | state); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 777 | } |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | bool Camera2Client::previewEnabled() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 781 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 782 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 783 | status_t res; |
| 784 | if ( (res = checkPid(__FUNCTION__) ) != OK) return false; |
| 785 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 786 | SharedParameters::Lock l(mParameters); |
| 787 | return l.mParameters.state == Parameters::PREVIEW; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | status_t Camera2Client::storeMetaDataInBuffers(bool enabled) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 791 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 792 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 793 | status_t res; |
| 794 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 795 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 796 | SharedParameters::Lock l(mParameters); |
| 797 | switch (l.mParameters.state) { |
| 798 | case Parameters::RECORD: |
| 799 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 800 | ALOGE("%s: Camera %d: Can't be called in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 801 | __FUNCTION__, mCameraId, |
| 802 | Parameters::getStateName(l.mParameters.state)); |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 803 | return INVALID_OPERATION; |
| 804 | default: |
| 805 | // OK |
| 806 | break; |
| 807 | } |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 808 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 809 | l.mParameters.storeMetadataInBuffers = enabled; |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 810 | |
| 811 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | status_t Camera2Client::startRecording() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 815 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 816 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 817 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 818 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 819 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 820 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 821 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 822 | return startRecordingL(l.mParameters, false); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | status_t Camera2Client::startRecordingL(Parameters ¶ms, bool restart) { |
| 826 | status_t res; |
Igor Murashkin | 22d58d3 | 2012-10-02 19:07:14 -0700 | [diff] [blame] | 827 | |
| 828 | ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart); |
| 829 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 830 | switch (params.state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 831 | case Parameters::STOPPED: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 832 | res = startPreviewL(params, false); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 833 | if (res != OK) return res; |
| 834 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 835 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 836 | // Ready to go |
| 837 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 838 | case Parameters::RECORD: |
| 839 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 840 | // OK to call this when recording is already on, just skip unless |
| 841 | // we're looking to restart |
| 842 | if (!restart) return OK; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 843 | break; |
| 844 | default: |
| 845 | ALOGE("%s: Camera %d: Can't start recording in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 846 | __FUNCTION__, mCameraId, |
| 847 | Parameters::getStateName(params.state)); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 848 | return INVALID_OPERATION; |
| 849 | }; |
| 850 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 851 | if (!params.storeMetadataInBuffers) { |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 852 | ALOGE("%s: Camera %d: Recording only supported in metadata mode, but " |
| 853 | "non-metadata recording mode requested!", __FUNCTION__, |
| 854 | mCameraId); |
| 855 | return INVALID_OPERATION; |
| 856 | } |
| 857 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 858 | if (!restart) { |
| 859 | mCameraService->playSound(CameraService::SOUND_RECORDING); |
| 860 | mStreamingProcessor->updateRecordingRequest(params); |
| 861 | if (res != OK) { |
| 862 | ALOGE("%s: Camera %d: Unable to update recording request: %s (%d)", |
| 863 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 864 | return res; |
| 865 | } |
| 866 | } |
Eino-Ville Talvala | 609acc0 | 2012-09-06 18:26:58 -0700 | [diff] [blame] | 867 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 868 | res = mStreamingProcessor->updateRecordingStream(params); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 869 | if (res != OK) { |
| 870 | ALOGE("%s: Camera %d: Unable to update recording stream: %s (%d)", |
| 871 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 872 | return res; |
| 873 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 874 | |
| 875 | Vector<uint8_t> outputStreams; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 876 | bool callbacksEnabled = params.previewCallbackFlags & |
| 877 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK; |
| 878 | if (callbacksEnabled) { |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 879 | res = mCallbackProcessor->updateStream(params); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 880 | if (res != OK) { |
| 881 | ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)", |
| 882 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 883 | return res; |
| 884 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 885 | outputStreams.push(getCallbackStreamId()); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 886 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 887 | outputStreams.push(getPreviewStreamId()); |
| 888 | outputStreams.push(getRecordingStreamId()); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 889 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 890 | res = mStreamingProcessor->startStream(StreamingProcessor::RECORD, |
| 891 | outputStreams); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 892 | if (res != OK) { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 893 | ALOGE("%s: Camera %d: Unable to start recording stream: %s (%d)", |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 894 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 895 | return res; |
| 896 | } |
| 897 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 898 | if (params.state < Parameters::RECORD) { |
| 899 | params.state = Parameters::RECORD; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 900 | } |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 901 | |
| 902 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void Camera2Client::stopRecording() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 906 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 907 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 908 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 909 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 910 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 911 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 912 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; |
| 913 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 914 | switch (l.mParameters.state) { |
| 915 | case Parameters::RECORD: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 916 | // OK to stop |
| 917 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 918 | case Parameters::STOPPED: |
| 919 | case Parameters::PREVIEW: |
| 920 | case Parameters::STILL_CAPTURE: |
| 921 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 922 | default: |
| 923 | ALOGE("%s: Camera %d: Can't stop recording in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 924 | __FUNCTION__, mCameraId, |
| 925 | Parameters::getStateName(l.mParameters.state)); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 926 | return; |
| 927 | }; |
| 928 | |
Eino-Ville Talvala | 609acc0 | 2012-09-06 18:26:58 -0700 | [diff] [blame] | 929 | mCameraService->playSound(CameraService::SOUND_RECORDING); |
| 930 | |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 931 | res = startPreviewL(l.mParameters, true); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 932 | if (res != OK) { |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 933 | ALOGE("%s: Camera %d: Unable to return to preview", |
| 934 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 935 | } |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | bool Camera2Client::recordingEnabled() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 939 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 940 | Mutex::Autolock icl(mICameraLock); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 941 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 942 | if ( checkPid(__FUNCTION__) != OK) return false; |
| 943 | |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 944 | return recordingEnabledL(); |
| 945 | } |
| 946 | |
| 947 | bool Camera2Client::recordingEnabledL() { |
| 948 | ATRACE_CALL(); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 949 | SharedParameters::Lock l(mParameters); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 950 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 951 | return (l.mParameters.state == Parameters::RECORD |
| 952 | || l.mParameters.state == Parameters::VIDEO_SNAPSHOT); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 956 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 957 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 958 | if ( checkPid(__FUNCTION__) != OK) return; |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 959 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 960 | mStreamingProcessor->releaseRecordingFrame(mem); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | status_t Camera2Client::autoFocus() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 964 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 965 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 966 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 967 | status_t res; |
| 968 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 969 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 970 | int triggerId; |
Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 971 | bool notifyImmediately = false; |
| 972 | bool notifySuccess = false; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 973 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 974 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 975 | if (l.mParameters.state < Parameters::PREVIEW) { |
| 976 | return INVALID_OPERATION; |
| 977 | } |
| 978 | |
Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 979 | /** |
| 980 | * If the camera does not support auto-focus, it is a no-op and |
| 981 | * onAutoFocus(boolean, Camera) callback will be called immediately |
| 982 | * with a fake value of success set to true. |
| 983 | */ |
| 984 | if (l.mParameters.focusMode == Parameters::FOCUS_MODE_FIXED) { |
Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 985 | notifyImmediately = true; |
| 986 | notifySuccess = true; |
| 987 | } |
| 988 | /** |
| 989 | * If we're in CAF mode, and AF has already been locked, just fire back |
| 990 | * the callback right away; the HAL would not send a notification since |
| 991 | * no state change would happen on a AF trigger. |
| 992 | */ |
| 993 | if ( (l.mParameters.focusMode == Parameters::FOCUS_MODE_CONTINUOUS_PICTURE || |
| 994 | l.mParameters.focusMode == Parameters::FOCUS_MODE_CONTINUOUS_VIDEO) && |
| 995 | l.mParameters.focusState == ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED ) { |
| 996 | notifyImmediately = true; |
| 997 | notifySuccess = true; |
| 998 | } |
| 999 | /** |
| 1000 | * Send immediate notification back to client |
| 1001 | */ |
| 1002 | if (notifyImmediately) { |
Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1003 | SharedCameraClient::Lock l(mSharedCameraClient); |
| 1004 | if (l.mCameraClient != 0) { |
| 1005 | l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, |
Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1006 | notifySuccess ? 1 : 0, 0); |
Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1007 | } |
Igor Murashkin | 5f0714e | 2012-10-08 18:05:12 -0700 | [diff] [blame] | 1008 | return OK; |
| 1009 | } |
Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1010 | /** |
| 1011 | * Handle quirk mode for AF in scene modes |
| 1012 | */ |
Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1013 | if (l.mParameters.quirks.triggerAfWithAuto && |
| 1014 | l.mParameters.sceneMode != ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED && |
Eino-Ville Talvala | ac0cd56 | 2012-10-16 12:58:21 -0700 | [diff] [blame] | 1015 | l.mParameters.focusMode != Parameters::FOCUS_MODE_AUTO && |
| 1016 | !l.mParameters.focusingAreas[0].isEmpty()) { |
Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1017 | ALOGV("%s: Quirk: Switching from focusMode %d to AUTO", |
| 1018 | __FUNCTION__, l.mParameters.focusMode); |
| 1019 | l.mParameters.shadowFocusMode = l.mParameters.focusMode; |
| 1020 | l.mParameters.focusMode = Parameters::FOCUS_MODE_AUTO; |
| 1021 | updateRequests(l.mParameters); |
| 1022 | } |
| 1023 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1024 | l.mParameters.currentAfTriggerId = ++l.mParameters.afTriggerCounter; |
| 1025 | triggerId = l.mParameters.currentAfTriggerId; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1026 | } |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1027 | syncWithDevice(); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1028 | |
| 1029 | mDevice->triggerAutofocus(triggerId); |
| 1030 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1031 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | status_t Camera2Client::cancelAutoFocus() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1035 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1036 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1037 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1038 | status_t res; |
| 1039 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 1040 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1041 | int triggerId; |
| 1042 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1043 | SharedParameters::Lock l(mParameters); |
| 1044 | triggerId = ++l.mParameters.afTriggerCounter; |
Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1045 | |
| 1046 | // When using triggerAfWithAuto quirk, may need to reset focus mode to |
Eino-Ville Talvala | ac0cd56 | 2012-10-16 12:58:21 -0700 | [diff] [blame] | 1047 | // the real state at this point. No need to cancel explicitly if |
| 1048 | // changing the AF mode. |
Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1049 | if (l.mParameters.shadowFocusMode != Parameters::FOCUS_MODE_INVALID) { |
| 1050 | ALOGV("%s: Quirk: Restoring focus mode to %d", __FUNCTION__, |
| 1051 | l.mParameters.shadowFocusMode); |
| 1052 | l.mParameters.focusMode = l.mParameters.shadowFocusMode; |
| 1053 | l.mParameters.shadowFocusMode = Parameters::FOCUS_MODE_INVALID; |
| 1054 | updateRequests(l.mParameters); |
Eino-Ville Talvala | ac0cd56 | 2012-10-16 12:58:21 -0700 | [diff] [blame] | 1055 | |
| 1056 | return OK; |
Eino-Ville Talvala | 95069fe | 2012-10-04 00:56:40 -0700 | [diff] [blame] | 1057 | } |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1058 | } |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1059 | syncWithDevice(); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1060 | |
| 1061 | mDevice->triggerCancelAutofocus(triggerId); |
| 1062 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1063 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Ben Murdoch | ff82370 | 2012-11-28 13:58:29 +0000 | [diff] [blame] | 1066 | status_t Camera2Client::takePicture(int msgType) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1067 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1068 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1069 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1070 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1071 | |
Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1072 | { |
| 1073 | SharedParameters::Lock l(mParameters); |
| 1074 | switch (l.mParameters.state) { |
| 1075 | case Parameters::DISCONNECTED: |
| 1076 | case Parameters::STOPPED: |
| 1077 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: |
| 1078 | ALOGE("%s: Camera %d: Cannot take picture without preview enabled", |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1079 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1080 | return INVALID_OPERATION; |
| 1081 | case Parameters::PREVIEW: |
| 1082 | // Good to go for takePicture |
| 1083 | res = commandStopFaceDetectionL(l.mParameters); |
| 1084 | if (res != OK) { |
| 1085 | ALOGE("%s: Camera %d: Unable to stop face detection for still capture", |
| 1086 | __FUNCTION__, mCameraId); |
| 1087 | return res; |
| 1088 | } |
| 1089 | l.mParameters.state = Parameters::STILL_CAPTURE; |
| 1090 | break; |
| 1091 | case Parameters::RECORD: |
| 1092 | // Good to go for video snapshot |
| 1093 | l.mParameters.state = Parameters::VIDEO_SNAPSHOT; |
| 1094 | break; |
| 1095 | case Parameters::STILL_CAPTURE: |
| 1096 | case Parameters::VIDEO_SNAPSHOT: |
| 1097 | ALOGE("%s: Camera %d: Already taking a picture", |
| 1098 | __FUNCTION__, mCameraId); |
| 1099 | return INVALID_OPERATION; |
| 1100 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1101 | |
Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1102 | ALOGV("%s: Camera %d: Starting picture capture", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1103 | |
Eino-Ville Talvala | b8d6efb | 2012-10-24 17:30:30 -0700 | [diff] [blame] | 1104 | res = mJpegProcessor->updateStream(l.mParameters); |
| 1105 | if (res != OK) { |
| 1106 | ALOGE("%s: Camera %d: Can't set up still image stream: %s (%d)", |
| 1107 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1108 | return res; |
| 1109 | } |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1110 | } |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1111 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1112 | // Need HAL to have correct settings before (possibly) triggering precapture |
| 1113 | syncWithDevice(); |
| 1114 | |
Igor Murashkin | aa9e3e0 | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 1115 | res = mCaptureSequencer->startCapture(msgType); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1116 | if (res != OK) { |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1117 | ALOGE("%s: Camera %d: Unable to start capture: %s (%d)", |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1118 | __FUNCTION__, mCameraId, strerror(-res), res); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1119 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1120 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1121 | return res; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | status_t Camera2Client::setParameters(const String8& params) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1125 | ATRACE_CALL(); |
Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1126 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1127 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1128 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1129 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 1130 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1131 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1132 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1133 | res = l.mParameters.set(params); |
| 1134 | if (res != OK) return res; |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1135 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1136 | res = updateRequests(l.mParameters); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1137 | |
| 1138 | return res; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1139 | } |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 1140 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1141 | String8 Camera2Client::getParameters() const { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1142 | ATRACE_CALL(); |
Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1143 | ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1144 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1145 | if ( checkPid(__FUNCTION__) != OK) return String8(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1146 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1147 | SharedParameters::ReadLock l(mParameters); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1148 | |
Eino-Ville Talvala | 8a42dd8 | 2012-10-02 13:30:04 -0700 | [diff] [blame] | 1149 | return l.mParameters.get(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | 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] | 1153 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1154 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1155 | status_t res; |
| 1156 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1157 | |
| 1158 | ALOGV("%s: Camera %d: Command %d (%d, %d)", __FUNCTION__, mCameraId, |
| 1159 | cmd, arg1, arg2); |
| 1160 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1161 | switch (cmd) { |
| 1162 | case CAMERA_CMD_START_SMOOTH_ZOOM: |
| 1163 | return commandStartSmoothZoomL(); |
| 1164 | case CAMERA_CMD_STOP_SMOOTH_ZOOM: |
| 1165 | return commandStopSmoothZoomL(); |
| 1166 | case CAMERA_CMD_SET_DISPLAY_ORIENTATION: |
| 1167 | return commandSetDisplayOrientationL(arg1); |
| 1168 | case CAMERA_CMD_ENABLE_SHUTTER_SOUND: |
| 1169 | return commandEnableShutterSoundL(arg1 == 1); |
| 1170 | case CAMERA_CMD_PLAY_RECORDING_SOUND: |
| 1171 | return commandPlayRecordingSoundL(); |
| 1172 | case CAMERA_CMD_START_FACE_DETECTION: |
| 1173 | return commandStartFaceDetectionL(arg1); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1174 | case CAMERA_CMD_STOP_FACE_DETECTION: { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1175 | SharedParameters::Lock l(mParameters); |
| 1176 | return commandStopFaceDetectionL(l.mParameters); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1177 | } |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1178 | case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG: |
| 1179 | return commandEnableFocusMoveMsgL(arg1 == 1); |
| 1180 | case CAMERA_CMD_PING: |
| 1181 | return commandPingL(); |
| 1182 | case CAMERA_CMD_SET_VIDEO_BUFFER_COUNT: |
| 1183 | return commandSetVideoBufferCountL(arg1); |
| 1184 | default: |
| 1185 | ALOGE("%s: Unknown command %d (arguments %d, %d)", |
| 1186 | __FUNCTION__, cmd, arg1, arg2); |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1187 | return BAD_VALUE; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1188 | } |
| 1189 | } |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1190 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1191 | status_t Camera2Client::commandStartSmoothZoomL() { |
| 1192 | ALOGE("%s: Unimplemented!", __FUNCTION__); |
| 1193 | return OK; |
| 1194 | } |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1195 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1196 | status_t Camera2Client::commandStopSmoothZoomL() { |
| 1197 | ALOGE("%s: Unimplemented!", __FUNCTION__); |
| 1198 | return OK; |
| 1199 | } |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1200 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1201 | status_t Camera2Client::commandSetDisplayOrientationL(int degrees) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1202 | int transform = Parameters::degToTransform(degrees, |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1203 | mCameraFacing == CAMERA_FACING_FRONT); |
| 1204 | if (transform == -1) { |
| 1205 | ALOGE("%s: Camera %d: Error setting %d as display orientation value", |
| 1206 | __FUNCTION__, mCameraId, degrees); |
| 1207 | return BAD_VALUE; |
| 1208 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1209 | SharedParameters::Lock l(mParameters); |
| 1210 | if (transform != l.mParameters.previewTransform && |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1211 | getPreviewStreamId() != NO_STREAM) { |
| 1212 | mDevice->setStreamTransform(getPreviewStreamId(), transform); |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1213 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1214 | l.mParameters.previewTransform = transform; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1215 | return OK; |
| 1216 | } |
| 1217 | |
| 1218 | status_t Camera2Client::commandEnableShutterSoundL(bool enable) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1219 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1220 | if (enable) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1221 | l.mParameters.playShutterSound = true; |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1222 | return OK; |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1225 | // Disabling shutter sound may not be allowed. In that case only |
| 1226 | // allow the mediaserver process to disable the sound. |
| 1227 | char value[PROPERTY_VALUE_MAX]; |
| 1228 | property_get("ro.camera.sound.forced", value, "0"); |
| 1229 | if (strncmp(value, "0", 2) != 0) { |
| 1230 | // Disabling shutter sound is not allowed. Deny if the current |
| 1231 | // process is not mediaserver. |
| 1232 | if (getCallingPid() != getpid()) { |
| 1233 | ALOGE("Failed to disable shutter sound. Permission denied (pid %d)", |
| 1234 | getCallingPid()); |
| 1235 | return PERMISSION_DENIED; |
| 1236 | } |
| 1237 | } |
| 1238 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1239 | l.mParameters.playShutterSound = false; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1240 | return OK; |
| 1241 | } |
| 1242 | |
| 1243 | status_t Camera2Client::commandPlayRecordingSoundL() { |
| 1244 | mCameraService->playSound(CameraService::SOUND_RECORDING); |
| 1245 | return OK; |
| 1246 | } |
| 1247 | |
Igor Murashkin | ddf3c50 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1248 | status_t Camera2Client::commandStartFaceDetectionL(int /*type*/) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1249 | ALOGV("%s: Camera %d: Starting face detection", |
| 1250 | __FUNCTION__, mCameraId); |
| 1251 | status_t res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1252 | SharedParameters::Lock l(mParameters); |
| 1253 | switch (l.mParameters.state) { |
| 1254 | case Parameters::DISCONNECTED: |
| 1255 | case Parameters::STOPPED: |
| 1256 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: |
| 1257 | case Parameters::STILL_CAPTURE: |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1258 | ALOGE("%s: Camera %d: Cannot start face detection without preview active", |
| 1259 | __FUNCTION__, mCameraId); |
| 1260 | return INVALID_OPERATION; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1261 | case Parameters::PREVIEW: |
| 1262 | case Parameters::RECORD: |
| 1263 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1264 | // Good to go for starting face detect |
| 1265 | break; |
| 1266 | } |
| 1267 | // Ignoring type |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1268 | if (l.mParameters.fastInfo.bestFaceDetectMode == |
Igor Murashkin | d32b99b | 2012-11-27 16:25:46 -0800 | [diff] [blame] | 1269 | ANDROID_STATISTICS_FACE_DETECT_MODE_OFF) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1270 | ALOGE("%s: Camera %d: Face detection not supported", |
| 1271 | __FUNCTION__, mCameraId); |
| 1272 | return INVALID_OPERATION; |
| 1273 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1274 | if (l.mParameters.enableFaceDetect) return OK; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1275 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1276 | l.mParameters.enableFaceDetect = true; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1277 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1278 | res = updateRequests(l.mParameters); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1279 | |
| 1280 | return res; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1283 | status_t Camera2Client::commandStopFaceDetectionL(Parameters ¶ms) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1284 | status_t res = OK; |
| 1285 | ALOGV("%s: Camera %d: Stopping face detection", |
| 1286 | __FUNCTION__, mCameraId); |
| 1287 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1288 | if (!params.enableFaceDetect) return OK; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1289 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1290 | params.enableFaceDetect = false; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1291 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1292 | if (params.state == Parameters::PREVIEW |
| 1293 | || params.state == Parameters::RECORD |
| 1294 | || params.state == Parameters::VIDEO_SNAPSHOT) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1295 | res = updateRequests(params); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | return res; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | status_t Camera2Client::commandEnableFocusMoveMsgL(bool enable) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1302 | SharedParameters::Lock l(mParameters); |
| 1303 | l.mParameters.enableFocusMoveMessages = enable; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1304 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1305 | return OK; |
| 1306 | } |
| 1307 | |
| 1308 | status_t Camera2Client::commandPingL() { |
| 1309 | // Always ping back if access is proper and device is alive |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1310 | SharedParameters::Lock l(mParameters); |
| 1311 | if (l.mParameters.state != Parameters::DISCONNECTED) { |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1312 | return OK; |
| 1313 | } else { |
| 1314 | return NO_INIT; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | status_t Camera2Client::commandSetVideoBufferCountL(size_t count) { |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 1319 | if (recordingEnabledL()) { |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1320 | ALOGE("%s: Camera %d: Error setting video buffer count after " |
| 1321 | "recording was started", __FUNCTION__, mCameraId); |
| 1322 | return INVALID_OPERATION; |
| 1323 | } |
| 1324 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1325 | return mStreamingProcessor->setRecordingBufferCount(count); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1328 | /** Device-related methods */ |
| 1329 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1330 | void Camera2Client::notifyError(int errorCode, int arg1, int arg2) { |
| 1331 | ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, arg1, arg2); |
| 1332 | } |
| 1333 | |
| 1334 | void Camera2Client::notifyShutter(int frameNumber, nsecs_t timestamp) { |
Igor Murashkin | ddf3c50 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1335 | (void)frameNumber; |
| 1336 | (void)timestamp; |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1337 | ALOGV("%s: Shutter notification for frame %d at time %lld", __FUNCTION__, |
| 1338 | frameNumber, timestamp); |
| 1339 | } |
| 1340 | |
| 1341 | void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { |
| 1342 | ALOGV("%s: Autofocus state now %d, last trigger %d", |
| 1343 | __FUNCTION__, newState, triggerId); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1344 | bool sendCompletedMessage = false; |
| 1345 | bool sendMovingMessage = false; |
| 1346 | |
| 1347 | bool success = false; |
| 1348 | bool afInMotion = false; |
| 1349 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1350 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | d6cc4a6 | 2012-10-16 10:17:30 -0700 | [diff] [blame] | 1351 | l.mParameters.focusState = newState; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1352 | switch (l.mParameters.focusMode) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1353 | case Parameters::FOCUS_MODE_AUTO: |
| 1354 | case Parameters::FOCUS_MODE_MACRO: |
| 1355 | // Don't send notifications upstream if they're not for the current AF |
| 1356 | // trigger. For example, if cancel was called in between, or if we |
| 1357 | // already sent a notification about this AF call. |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1358 | if (triggerId != l.mParameters.currentAfTriggerId) break; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1359 | switch (newState) { |
| 1360 | case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED: |
| 1361 | success = true; |
| 1362 | // no break |
| 1363 | case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: |
| 1364 | sendCompletedMessage = true; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1365 | l.mParameters.currentAfTriggerId = -1; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1366 | break; |
| 1367 | case ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN: |
| 1368 | // Just starting focusing, ignore |
| 1369 | break; |
| 1370 | case ANDROID_CONTROL_AF_STATE_INACTIVE: |
| 1371 | case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN: |
| 1372 | case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED: |
| 1373 | default: |
| 1374 | // Unexpected in AUTO/MACRO mode |
| 1375 | ALOGE("%s: Unexpected AF state transition in AUTO/MACRO mode: %d", |
| 1376 | __FUNCTION__, newState); |
| 1377 | break; |
| 1378 | } |
| 1379 | break; |
| 1380 | case Parameters::FOCUS_MODE_CONTINUOUS_VIDEO: |
| 1381 | case Parameters::FOCUS_MODE_CONTINUOUS_PICTURE: |
| 1382 | switch (newState) { |
| 1383 | case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED: |
| 1384 | success = true; |
| 1385 | // no break |
| 1386 | case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: |
| 1387 | // Don't send notifications upstream if they're not for |
| 1388 | // the current AF trigger. For example, if cancel was |
| 1389 | // called in between, or if we already sent a |
| 1390 | // notification about this AF call. |
| 1391 | // Send both a 'AF done' callback and a 'AF move' callback |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1392 | if (triggerId != l.mParameters.currentAfTriggerId) break; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1393 | sendCompletedMessage = true; |
| 1394 | afInMotion = false; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1395 | if (l.mParameters.enableFocusMoveMessages && |
| 1396 | l.mParameters.afInMotion) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1397 | sendMovingMessage = true; |
| 1398 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1399 | l.mParameters.currentAfTriggerId = -1; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1400 | break; |
| 1401 | case ANDROID_CONTROL_AF_STATE_INACTIVE: |
| 1402 | // Cancel was called, or we switched state; care if |
| 1403 | // currently moving |
| 1404 | afInMotion = false; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1405 | if (l.mParameters.enableFocusMoveMessages && |
| 1406 | l.mParameters.afInMotion) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1407 | sendMovingMessage = true; |
| 1408 | } |
| 1409 | break; |
| 1410 | case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN: |
| 1411 | // Start passive scan, inform upstream |
| 1412 | afInMotion = true; |
| 1413 | // no break |
| 1414 | case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED: |
| 1415 | // Stop passive scan, inform upstream |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1416 | if (l.mParameters.enableFocusMoveMessages) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1417 | sendMovingMessage = true; |
| 1418 | } |
| 1419 | break; |
| 1420 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1421 | l.mParameters.afInMotion = afInMotion; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1422 | break; |
| 1423 | case Parameters::FOCUS_MODE_EDOF: |
| 1424 | case Parameters::FOCUS_MODE_INFINITY: |
| 1425 | case Parameters::FOCUS_MODE_FIXED: |
| 1426 | default: |
| 1427 | if (newState != ANDROID_CONTROL_AF_STATE_INACTIVE) { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1428 | ALOGE("%s: Unexpected AF state change %d " |
| 1429 | "(ID %d) in focus mode %d", |
| 1430 | __FUNCTION__, newState, triggerId, |
| 1431 | l.mParameters.focusMode); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | } |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1435 | if (sendMovingMessage) { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1436 | SharedCameraClient::Lock l(mSharedCameraClient); |
| 1437 | if (l.mCameraClient != 0) { |
| 1438 | l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS_MOVE, |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1439 | afInMotion ? 1 : 0, 0); |
| 1440 | } |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1441 | } |
Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 1442 | if (sendCompletedMessage) { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1443 | SharedCameraClient::Lock l(mSharedCameraClient); |
| 1444 | if (l.mCameraClient != 0) { |
| 1445 | l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, |
| 1446 | success ? 1 : 0, 0); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1447 | } |
Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 1448 | } |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | void Camera2Client::notifyAutoExposure(uint8_t newState, int triggerId) { |
| 1452 | ALOGV("%s: Autoexposure state now %d, last trigger %d", |
| 1453 | __FUNCTION__, newState, triggerId); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1454 | mCaptureSequencer->notifyAutoExposure(newState, triggerId); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | void Camera2Client::notifyAutoWhitebalance(uint8_t newState, int triggerId) { |
Igor Murashkin | ddf3c50 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1458 | (void)newState; |
| 1459 | (void)triggerId; |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1460 | ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", |
| 1461 | __FUNCTION__, newState, triggerId); |
| 1462 | } |
| 1463 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1464 | int Camera2Client::getCameraId() const { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1465 | return mCameraId; |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1468 | const sp<Camera2Device>& Camera2Client::getCameraDevice() { |
| 1469 | return mDevice; |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Eino-Ville Talvala | 609acc0 | 2012-09-06 18:26:58 -0700 | [diff] [blame] | 1472 | const sp<CameraService>& Camera2Client::getCameraService() { |
| 1473 | return mCameraService; |
| 1474 | } |
| 1475 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1476 | camera2::SharedParameters& Camera2Client::getParameters() { |
| 1477 | return mParameters; |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1480 | int Camera2Client::getPreviewStreamId() const { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1481 | return mStreamingProcessor->getPreviewStreamId(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | int Camera2Client::getCaptureStreamId() const { |
| 1485 | return mJpegProcessor->getStreamId(); |
| 1486 | } |
| 1487 | |
| 1488 | int Camera2Client::getCallbackStreamId() const { |
| 1489 | return mCallbackProcessor->getStreamId(); |
| 1490 | } |
| 1491 | |
| 1492 | int Camera2Client::getRecordingStreamId() const { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1493 | return mStreamingProcessor->getRecordingStreamId(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | int Camera2Client::getZslStreamId() const { |
| 1497 | return mZslProcessor->getStreamId(); |
| 1498 | } |
| 1499 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1500 | status_t Camera2Client::registerFrameListener(int32_t minId, int32_t maxId, |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1501 | wp<camera2::FrameProcessor::FilteredListener> listener) { |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1502 | return mFrameProcessor->registerListener(minId, maxId, listener); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1505 | status_t Camera2Client::removeFrameListener(int32_t minId, int32_t maxId, |
| 1506 | wp<camera2::FrameProcessor::FilteredListener> listener) { |
| 1507 | return mFrameProcessor->removeListener(minId, maxId, listener); |
| 1508 | } |
| 1509 | |
| 1510 | status_t Camera2Client::stopStream() { |
| 1511 | return mStreamingProcessor->stopStream(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1514 | Camera2Client::SharedCameraClient::Lock::Lock(SharedCameraClient &client): |
| 1515 | mCameraClient(client.mCameraClient), |
| 1516 | mSharedClient(client) { |
| 1517 | mSharedClient.mCameraClientLock.lock(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1520 | Camera2Client::SharedCameraClient::Lock::~Lock() { |
| 1521 | mSharedClient.mCameraClientLock.unlock(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 1524 | Camera2Client::SharedCameraClient::SharedCameraClient(const sp<ICameraClient>&client): |
| 1525 | mCameraClient(client) { |
| 1526 | } |
| 1527 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1528 | Camera2Client::SharedCameraClient& Camera2Client::SharedCameraClient::operator=( |
| 1529 | const sp<ICameraClient>&client) { |
| 1530 | Mutex::Autolock l(mCameraClientLock); |
| 1531 | mCameraClient = client; |
| 1532 | return *this; |
| 1533 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1534 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1535 | void Camera2Client::SharedCameraClient::clear() { |
| 1536 | Mutex::Autolock l(mCameraClientLock); |
| 1537 | mCameraClient.clear(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1540 | const int32_t Camera2Client::kPreviewRequestIdStart; |
| 1541 | const int32_t Camera2Client::kPreviewRequestIdEnd; |
| 1542 | const int32_t Camera2Client::kRecordingRequestIdStart; |
| 1543 | const int32_t Camera2Client::kRecordingRequestIdEnd; |
| 1544 | const int32_t Camera2Client::kCaptureRequestIdStart; |
| 1545 | const int32_t Camera2Client::kCaptureRequestIdEnd; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1546 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1547 | /** Utility methods */ |
| 1548 | |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 1549 | status_t Camera2Client::updateRequests(Parameters ¶ms) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1550 | status_t res; |
| 1551 | |
Igor Murashkin | 22d58d3 | 2012-10-02 19:07:14 -0700 | [diff] [blame] | 1552 | ALOGV("%s: Camera %d: state = %d", __FUNCTION__, getCameraId(), params.state); |
| 1553 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1554 | res = mStreamingProcessor->incrementStreamingIds(); |
| 1555 | if (res != OK) { |
| 1556 | ALOGE("%s: Camera %d: Unable to increment request IDs: %s (%d)", |
| 1557 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1558 | return res; |
| 1559 | } |
| 1560 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1561 | res = mStreamingProcessor->updatePreviewRequest(params); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1562 | if (res != OK) { |
| 1563 | ALOGE("%s: Camera %d: Unable to update preview request: %s (%d)", |
| 1564 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1565 | return res; |
| 1566 | } |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1567 | res = mStreamingProcessor->updateRecordingRequest(params); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1568 | if (res != OK) { |
| 1569 | ALOGE("%s: Camera %d: Unable to update recording request: %s (%d)", |
| 1570 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1571 | return res; |
| 1572 | } |
| 1573 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1574 | if (params.state == Parameters::PREVIEW) { |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 1575 | res = startPreviewL(params, true); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1576 | if (res != OK) { |
| 1577 | ALOGE("%s: Camera %d: Error streaming new preview request: %s (%d)", |
| 1578 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1579 | return res; |
| 1580 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1581 | } else if (params.state == Parameters::RECORD || |
| 1582 | params.state == Parameters::VIDEO_SNAPSHOT) { |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 1583 | res = startRecordingL(params, true); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1584 | if (res != OK) { |
| 1585 | ALOGE("%s: Camera %d: Error streaming new record request: %s (%d)", |
| 1586 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1587 | return res; |
| 1588 | } |
| 1589 | } |
| 1590 | return res; |
| 1591 | } |
| 1592 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1593 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1594 | size_t Camera2Client::calculateBufferSize(int width, int height, |
| 1595 | int format, int stride) { |
| 1596 | switch (format) { |
| 1597 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: // NV16 |
| 1598 | return width * height * 2; |
| 1599 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: // NV21 |
| 1600 | return width * height * 3 / 2; |
| 1601 | case HAL_PIXEL_FORMAT_YCbCr_422_I: // YUY2 |
| 1602 | return width * height * 2; |
| 1603 | case HAL_PIXEL_FORMAT_YV12: { // YV12 |
| 1604 | size_t ySize = stride * height; |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 1605 | size_t uvStride = (stride / 2 + 0xF) & ~0xF; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1606 | size_t uvSize = uvStride * height / 2; |
| 1607 | return ySize + uvSize * 2; |
| 1608 | } |
| 1609 | case HAL_PIXEL_FORMAT_RGB_565: |
| 1610 | return width * height * 2; |
| 1611 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 1612 | return width * height * 4; |
| 1613 | case HAL_PIXEL_FORMAT_RAW_SENSOR: |
| 1614 | return width * height * 2; |
| 1615 | default: |
| 1616 | ALOGE("%s: Unknown preview format: %x", |
| 1617 | __FUNCTION__, format); |
| 1618 | return 0; |
| 1619 | } |
| 1620 | } |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1621 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1622 | status_t Camera2Client::syncWithDevice() { |
| 1623 | ATRACE_CALL(); |
Eino-Ville Talvala | 43b7ac6 | 2012-10-23 09:09:01 -0700 | [diff] [blame] | 1624 | const nsecs_t kMaxSyncTimeout = 500000000; // 500 ms |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 1625 | status_t res; |
| 1626 | |
| 1627 | int32_t activeRequestId = mStreamingProcessor->getActiveRequestId(); |
| 1628 | if (activeRequestId == 0) return OK; |
| 1629 | |
| 1630 | res = mDevice->waitUntilRequestReceived(activeRequestId, kMaxSyncTimeout); |
| 1631 | if (res == TIMED_OUT) { |
| 1632 | ALOGE("%s: Camera %d: Timed out waiting sync with HAL", |
| 1633 | __FUNCTION__, mCameraId); |
| 1634 | } else if (res != OK) { |
| 1635 | ALOGE("%s: Camera %d: Error while waiting to sync with HAL", |
| 1636 | __FUNCTION__, mCameraId); |
| 1637 | } |
| 1638 | return res; |
| 1639 | } |
| 1640 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1641 | } // namespace android |