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 | |
| 17 | #define LOG_TAG "Camera2Client" |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 20 | |
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> |
| 25 | #include <gui/SurfaceTextureClient.h> |
| 26 | #include <gui/Surface.h> |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 27 | #include <media/hardware/MetadataBufferType.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 28 | |
| 29 | #include "Camera2Client.h" |
| 30 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 31 | #define ALOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); |
| 32 | #define ALOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); |
| 33 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | |
| 36 | using namespace camera2; |
| 37 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 38 | static int getCallingPid() { |
| 39 | return IPCThreadState::self()->getCallingPid(); |
| 40 | } |
| 41 | |
| 42 | static int getCallingUid() { |
| 43 | return IPCThreadState::self()->getCallingUid(); |
| 44 | } |
| 45 | |
| 46 | // Interface used by CameraService |
| 47 | |
| 48 | Camera2Client::Camera2Client(const sp<CameraService>& cameraService, |
| 49 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 50 | int cameraId, |
| 51 | int cameraFacing, |
| 52 | int clientPid): |
| 53 | Client(cameraService, cameraClient, |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 54 | cameraId, cameraFacing, clientPid), |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 55 | mSharedCameraClient(cameraClient), |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 56 | mParameters(cameraId, cameraFacing), |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 57 | mPreviewStreamId(NO_STREAM), |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 58 | mRecordingStreamId(NO_STREAM), |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 59 | mRecordingHeapCount(kDefaultRecordingHeapCount) |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 60 | { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 61 | ATRACE_CALL(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 62 | ALOGV("%s: Created client for camera %d", __FUNCTION__, cameraId); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 63 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 64 | mDevice = new Camera2Device(cameraId); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 65 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 66 | SharedParameters::Lock l(mParameters); |
| 67 | l.mParameters.state = Parameters::DISCONNECTED; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 70 | status_t Camera2Client::checkPid(const char* checkLocation) const { |
| 71 | int callingPid = getCallingPid(); |
| 72 | if (callingPid == mClientPid) return NO_ERROR; |
| 73 | |
| 74 | ALOGE("%s: attempt to use a locked camera from a different process" |
| 75 | " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid); |
| 76 | return PERMISSION_DENIED; |
| 77 | } |
| 78 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 79 | status_t Camera2Client::initialize(camera_module_t *module) |
| 80 | { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 81 | ATRACE_CALL(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 82 | ALOGV("%s: Initializing client for camera %d", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 83 | status_t res; |
| 84 | |
| 85 | res = mDevice->initialize(module); |
| 86 | if (res != OK) { |
| 87 | ALOGE("%s: Camera %d: unable to initialize device: %s (%d)", |
| 88 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 89 | return NO_INIT; |
| 90 | } |
| 91 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 92 | res = mDevice->setNotifyCallback(this); |
| 93 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 94 | SharedParameters::Lock l(mParameters); |
| 95 | |
| 96 | res = l.mParameters.initialize(&(mDevice->info())); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 97 | if (res != OK) { |
| 98 | ALOGE("%s: Camera %d: unable to build defaults: %s (%d)", |
| 99 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 100 | return NO_INIT; |
| 101 | } |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 102 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 103 | mFrameProcessor = new FrameProcessor(this); |
| 104 | String8 frameThreadName = String8::format("Camera2Client[%d]::FrameProcessor", |
| 105 | mCameraId); |
| 106 | mFrameProcessor->run(frameThreadName.string()); |
| 107 | |
| 108 | mCaptureProcessor = new CaptureProcessor(this); |
| 109 | String8 captureThreadName = |
| 110 | String8::format("Camera2Client[%d]::CaptureProcessor", mCameraId); |
| 111 | mCaptureProcessor->run(captureThreadName.string()); |
| 112 | |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 113 | mCallbackProcessor = new CallbackProcessor(this); |
| 114 | String8 callbackThreadName = |
| 115 | String8::format("Camera2Client[%d]::CallbackProcessor", mCameraId); |
| 116 | mCallbackProcessor->run(callbackThreadName.string()); |
| 117 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 118 | if (gLogLevel >= 1) { |
| 119 | ALOGD("%s: Default parameters converted from camera %d:", __FUNCTION__, |
| 120 | mCameraId); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 121 | ALOGD("%s", l.mParameters.paramsFlattened.string()); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 124 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | Camera2Client::~Camera2Client() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 128 | ATRACE_CALL(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 129 | ALOGV("%s: Camera %d: Shutting down client.", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 130 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 131 | mDestructionStarted = true; |
| 132 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 133 | // Rewrite mClientPid to allow shutdown by CameraService |
| 134 | mClientPid = getCallingPid(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 135 | disconnect(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 136 | |
| 137 | mFrameProcessor->requestExit(); |
| 138 | ALOGV("%s: Camera %d: Shutdown complete", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | status_t Camera2Client::dump(int fd, const Vector<String16>& args) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 142 | String8 result; |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 143 | result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n", |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 144 | mCameraId, |
| 145 | getCameraClient()->asBinder().get(), |
| 146 | mClientPid); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 147 | result.append(" State: "); |
| 148 | #define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break; |
| 149 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 150 | const Parameters& p = mParameters.unsafeAccess(); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 151 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 152 | result.append(Parameters::getStateName(p.state)); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 153 | |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 154 | result.append("\n Current parameters:\n"); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 155 | result.appendFormat(" Preview size: %d x %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 156 | p.previewWidth, p.previewHeight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 157 | result.appendFormat(" Preview FPS range: %d - %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 158 | p.previewFpsRange[0], p.previewFpsRange[1]); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 159 | result.appendFormat(" Preview HAL pixel format: 0x%x\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 160 | p.previewFormat); |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 161 | result.appendFormat(" Preview transform: %x\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 162 | p.previewTransform); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 163 | result.appendFormat(" Picture size: %d x %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 164 | p.pictureWidth, p.pictureHeight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 165 | result.appendFormat(" Jpeg thumbnail size: %d x %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 166 | p.jpegThumbSize[0], p.jpegThumbSize[1]); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 167 | result.appendFormat(" Jpeg quality: %d, thumbnail quality: %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 168 | p.jpegQuality, p.jpegThumbQuality); |
| 169 | result.appendFormat(" Jpeg rotation: %d\n", p.jpegRotation); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 170 | result.appendFormat(" GPS tags %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 171 | p.gpsEnabled ? "enabled" : "disabled"); |
| 172 | if (p.gpsEnabled) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 173 | 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] | 174 | p.gpsCoordinates[0], p.gpsCoordinates[1], |
| 175 | p.gpsCoordinates[2]); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 176 | result.appendFormat(" GPS timestamp: %lld\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 177 | p.gpsTimestamp); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 178 | result.appendFormat(" GPS processing method: %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 179 | p.gpsProcessingMethod.string()); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | result.append(" White balance mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 183 | switch (p.wbMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 184 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_AUTO) |
| 185 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_INCANDESCENT) |
| 186 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_FLUORESCENT) |
| 187 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_WARM_FLUORESCENT) |
| 188 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_DAYLIGHT) |
| 189 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_CLOUDY_DAYLIGHT) |
| 190 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_TWILIGHT) |
| 191 | CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_SHADE) |
| 192 | default: result.append("UNKNOWN\n"); |
| 193 | } |
| 194 | |
| 195 | result.append(" Effect mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 196 | switch (p.effectMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 197 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_OFF) |
| 198 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MONO) |
| 199 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_NEGATIVE) |
| 200 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_SOLARIZE) |
| 201 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_SEPIA) |
| 202 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_POSTERIZE) |
| 203 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_WHITEBOARD) |
| 204 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_BLACKBOARD) |
| 205 | CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_AQUA) |
| 206 | default: result.append("UNKNOWN\n"); |
| 207 | } |
| 208 | |
| 209 | result.append(" Antibanding mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 210 | switch (p.antibandingMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 211 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_AUTO) |
| 212 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_OFF) |
| 213 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_50HZ) |
| 214 | CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_60HZ) |
| 215 | default: result.append("UNKNOWN\n"); |
| 216 | } |
| 217 | |
| 218 | result.append(" Scene mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 219 | switch (p.sceneMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 220 | case ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED: |
| 221 | result.append("AUTO\n"); break; |
| 222 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_ACTION) |
| 223 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PORTRAIT) |
| 224 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_LANDSCAPE) |
| 225 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT) |
| 226 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT) |
| 227 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_THEATRE) |
| 228 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BEACH) |
| 229 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SNOW) |
| 230 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SUNSET) |
| 231 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO) |
| 232 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_FIREWORKS) |
| 233 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SPORTS) |
| 234 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PARTY) |
| 235 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT) |
| 236 | CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BARCODE) |
| 237 | default: result.append("UNKNOWN\n"); |
| 238 | } |
| 239 | |
| 240 | result.append(" Flash mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 241 | switch (p.flashMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 242 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_OFF) |
| 243 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_AUTO) |
| 244 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_ON) |
| 245 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_TORCH) |
| 246 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_RED_EYE) |
| 247 | CASE_APPEND_ENUM(Parameters::FLASH_MODE_INVALID) |
| 248 | default: result.append("UNKNOWN\n"); |
| 249 | } |
| 250 | |
| 251 | result.append(" Focus mode: "); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 252 | switch (p.focusMode) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 253 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_AUTO) |
| 254 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_MACRO) |
| 255 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_VIDEO) |
| 256 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_PICTURE) |
| 257 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_EDOF) |
| 258 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INFINITY) |
| 259 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_FIXED) |
| 260 | CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INVALID) |
| 261 | default: result.append("UNKNOWN\n"); |
| 262 | } |
| 263 | |
| 264 | result.append(" Focusing areas:\n"); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 265 | for (size_t i = 0; i < p.focusingAreas.size(); i++) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 266 | result.appendFormat(" [ (%d, %d, %d, %d), weight %d ]\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 267 | p.focusingAreas[i].left, |
| 268 | p.focusingAreas[i].top, |
| 269 | p.focusingAreas[i].right, |
| 270 | p.focusingAreas[i].bottom, |
| 271 | p.focusingAreas[i].weight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | result.appendFormat(" Exposure compensation index: %d\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 275 | p.exposureCompensation); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 276 | |
| 277 | result.appendFormat(" AE lock %s, AWB lock %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 278 | p.autoExposureLock ? "enabled" : "disabled", |
| 279 | p.autoWhiteBalanceLock ? "enabled" : "disabled" ); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 280 | |
| 281 | result.appendFormat(" Metering areas:\n"); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 282 | for (size_t i = 0; i < p.meteringAreas.size(); i++) { |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 283 | result.appendFormat(" [ (%d, %d, %d, %d), weight %d ]\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 284 | p.meteringAreas[i].left, |
| 285 | p.meteringAreas[i].top, |
| 286 | p.meteringAreas[i].right, |
| 287 | p.meteringAreas[i].bottom, |
| 288 | p.meteringAreas[i].weight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 291 | result.appendFormat(" Zoom index: %d\n", p.zoom); |
| 292 | result.appendFormat(" Video size: %d x %d\n", p.videoWidth, |
| 293 | p.videoHeight); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 294 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 295 | result.appendFormat(" Recording hint is %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 296 | p.recordingHint ? "set" : "not set"); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 297 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 298 | result.appendFormat(" Video stabilization is %s\n", |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 299 | p.videoStabilization ? "enabled" : "disabled"); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 300 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 301 | result.append(" Current streams:\n"); |
| 302 | result.appendFormat(" Preview stream ID: %d\n", mPreviewStreamId); |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 303 | result.appendFormat(" Capture stream ID: %d\n", |
| 304 | mCaptureProcessor->getStreamId()); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 305 | result.appendFormat(" Recording stream ID: %d\n", mRecordingStreamId); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 306 | |
| 307 | result.append(" Current requests:\n"); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 308 | if (mPreviewRequest.entryCount() != 0) { |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 309 | result.append(" Preview request:\n"); |
| 310 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 311 | mPreviewRequest.dump(fd, 2, 6); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 312 | } else { |
| 313 | result.append(" Preview request: undefined\n"); |
| 314 | write(fd, result.string(), result.size()); |
| 315 | } |
| 316 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 317 | if (mCaptureRequest.entryCount() != 0) { |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 318 | result = " Capture request:\n"; |
| 319 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 320 | mCaptureRequest.dump(fd, 2, 6); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 321 | } else { |
| 322 | result = " Capture request: undefined\n"; |
| 323 | write(fd, result.string(), result.size()); |
| 324 | } |
| 325 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 326 | if (mRecordingRequest.entryCount() != 0) { |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 327 | result = " Recording request:\n"; |
| 328 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 329 | mRecordingRequest.dump(fd, 2, 6); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 330 | } else { |
| 331 | result = " Recording request: undefined\n"; |
| 332 | write(fd, result.string(), result.size()); |
| 333 | } |
| 334 | |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 335 | mFrameProcessor->dump(fd, args); |
| 336 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 337 | result = " Device dump:\n"; |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 338 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 339 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 340 | status_t res = mDevice->dump(fd, args); |
| 341 | if (res != OK) { |
| 342 | result = String8::format(" Error dumping device: %s (%d)", |
| 343 | strerror(-res), res); |
| 344 | write(fd, result.string(), result.size()); |
| 345 | } |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 346 | |
| 347 | #undef CASE_APPEND_ENUM |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 348 | return NO_ERROR; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | // ICamera interface |
| 352 | |
| 353 | void Camera2Client::disconnect() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 354 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 355 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 356 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 357 | status_t res; |
| 358 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 359 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 360 | if (mDevice == 0) return; |
| 361 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 362 | stopPreviewL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 363 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 364 | if (mPreviewStreamId != NO_STREAM) { |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 365 | mDevice->deleteStream(mPreviewStreamId); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 366 | mPreviewStreamId = NO_STREAM; |
| 367 | } |
| 368 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 369 | mCaptureProcessor->deleteStream(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 370 | |
Eino-Ville Talvala | 898a9a9 | 2012-07-20 11:05:20 -0700 | [diff] [blame] | 371 | if (mRecordingStreamId != NO_STREAM) { |
| 372 | mDevice->deleteStream(mRecordingStreamId); |
| 373 | mRecordingStreamId = NO_STREAM; |
| 374 | } |
| 375 | |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 376 | mCallbackProcessor->deleteStream(); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 377 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 378 | mDevice.clear(); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 379 | SharedParameters::Lock l(mParameters); |
| 380 | l.mParameters.state = Parameters::DISCONNECTED; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 381 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 382 | CameraService::Client::disconnect(); |
| 383 | } |
| 384 | |
| 385 | status_t Camera2Client::connect(const sp<ICameraClient>& client) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 386 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 387 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 388 | Mutex::Autolock icl(mICameraLock); |
| 389 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 390 | if (mClientPid != 0 && getCallingPid() != mClientPid) { |
| 391 | ALOGE("%s: Camera %d: Connection attempt from pid %d; " |
| 392 | "current locked to pid %d", __FUNCTION__, |
| 393 | mCameraId, getCallingPid(), mClientPid); |
| 394 | return BAD_VALUE; |
| 395 | } |
| 396 | |
| 397 | mClientPid = getCallingPid(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 398 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 399 | mCameraClient = client; |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 400 | mSharedCameraClient = client; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 401 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 402 | SharedParameters::Lock l(mParameters); |
| 403 | l.mParameters.state = Parameters::STOPPED; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 404 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 405 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | status_t Camera2Client::lock() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 409 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 410 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 411 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 412 | ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d", |
| 413 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 414 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 415 | if (mClientPid == 0) { |
| 416 | mClientPid = getCallingPid(); |
| 417 | return OK; |
| 418 | } |
| 419 | |
| 420 | if (mClientPid != getCallingPid()) { |
| 421 | ALOGE("%s: Camera %d: Lock call from pid %d; currently locked to pid %d", |
| 422 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
| 423 | return EBUSY; |
| 424 | } |
| 425 | |
| 426 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | status_t Camera2Client::unlock() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 430 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 431 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 432 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 433 | ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d", |
| 434 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 435 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 436 | // TODO: Check for uninterruptable conditions |
| 437 | |
| 438 | if (mClientPid == getCallingPid()) { |
| 439 | mClientPid = 0; |
| 440 | mCameraClient.clear(); |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 441 | mSharedCameraClient.clear(); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 442 | return OK; |
| 443 | } |
| 444 | |
| 445 | ALOGE("%s: Camera %d: Unlock call from pid %d; currently locked to pid %d", |
| 446 | __FUNCTION__, mCameraId, getCallingPid(), mClientPid); |
| 447 | return EBUSY; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 450 | status_t Camera2Client::setPreviewDisplay( |
| 451 | const sp<Surface>& surface) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 452 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 453 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 454 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 455 | status_t res; |
| 456 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 457 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 458 | sp<IBinder> binder; |
| 459 | sp<ANativeWindow> window; |
| 460 | if (surface != 0) { |
| 461 | binder = surface->asBinder(); |
| 462 | window = surface; |
| 463 | } |
| 464 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 465 | return setPreviewWindowL(binder,window); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 468 | status_t Camera2Client::setPreviewTexture( |
| 469 | const sp<ISurfaceTexture>& surfaceTexture) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 470 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 471 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 472 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 473 | status_t res; |
| 474 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 475 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 476 | sp<IBinder> binder; |
| 477 | sp<ANativeWindow> window; |
| 478 | if (surfaceTexture != 0) { |
| 479 | binder = surfaceTexture->asBinder(); |
| 480 | window = new SurfaceTextureClient(surfaceTexture); |
| 481 | } |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 482 | return setPreviewWindowL(binder, window); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 485 | status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 486 | sp<ANativeWindow> window) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 487 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 488 | status_t res; |
| 489 | |
| 490 | if (binder == mPreviewSurface) { |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 491 | ALOGV("%s: Camera %d: New window is same as old window", |
| 492 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 493 | return NO_ERROR; |
| 494 | } |
| 495 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 496 | SharedParameters::Lock l(mParameters); |
| 497 | switch (l.mParameters.state) { |
| 498 | case Parameters::DISCONNECTED: |
| 499 | case Parameters::RECORD: |
| 500 | case Parameters::STILL_CAPTURE: |
| 501 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 502 | 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] | 503 | __FUNCTION__, mCameraId, |
| 504 | Parameters::getStateName(l.mParameters.state)); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 505 | return INVALID_OPERATION; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 506 | case Parameters::STOPPED: |
| 507 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 508 | // OK |
| 509 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 510 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 511 | // Already running preview - need to stop and create a new stream |
| 512 | // TODO: Optimize this so that we don't wait for old stream to drain |
| 513 | // before spinning up new stream |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 514 | mDevice->clearStreamingRequest(); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 515 | l.mParameters.state = Parameters::WAITING_FOR_PREVIEW_WINDOW; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 516 | break; |
| 517 | } |
| 518 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 519 | if (mPreviewStreamId != NO_STREAM) { |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 520 | res = mDevice->waitUntilDrained(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 521 | if (res != OK) { |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 522 | ALOGE("%s: Error waiting for preview to drain: %s (%d)", |
| 523 | __FUNCTION__, strerror(-res), res); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 524 | return res; |
| 525 | } |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 526 | res = mDevice->deleteStream(mPreviewStreamId); |
| 527 | if (res != OK) { |
| 528 | ALOGE("%s: Unable to delete old preview stream: %s (%d)", |
| 529 | __FUNCTION__, strerror(-res), res); |
| 530 | return res; |
| 531 | } |
| 532 | mPreviewStreamId = NO_STREAM; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 535 | mPreviewSurface = binder; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 536 | mPreviewWindow = window; |
Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 537 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 538 | if (l.mParameters.state == Parameters::WAITING_FOR_PREVIEW_WINDOW) { |
| 539 | return startPreviewL(l.mParameters, false); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 542 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void Camera2Client::setPreviewCallbackFlag(int flag) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 546 | ATRACE_CALL(); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 547 | ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 548 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 549 | status_t res; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 550 | if ( checkPid(__FUNCTION__) != OK) return; |
| 551 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 552 | SharedParameters::Lock l(mParameters); |
| 553 | setPreviewCallbackFlagL(l.mParameters, flag); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void Camera2Client::setPreviewCallbackFlagL(Parameters ¶ms, int flag) { |
| 557 | status_t res = OK; |
| 558 | if (flag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) { |
| 559 | ALOGV("%s: setting oneshot", __FUNCTION__); |
| 560 | params.previewCallbackOneShot = true; |
| 561 | } |
| 562 | if (params.previewCallbackFlags != (uint32_t)flag) { |
| 563 | params.previewCallbackFlags = flag; |
| 564 | switch(params.state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 565 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 566 | res = startPreviewL(params, true); |
| 567 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 568 | case Parameters::RECORD: |
| 569 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 570 | res = startRecordingL(params, true); |
| 571 | break; |
| 572 | default: |
| 573 | break; |
| 574 | } |
| 575 | if (res != OK) { |
| 576 | ALOGE("%s: Camera %d: Unable to refresh request in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 577 | __FUNCTION__, mCameraId, |
| 578 | Parameters::getStateName(params.state)); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | status_t Camera2Client::startPreview() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 585 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 586 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 587 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 588 | status_t res; |
| 589 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 590 | SharedParameters::Lock l(mParameters); |
| 591 | return startPreviewL(l.mParameters, false); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 592 | } |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 593 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 594 | status_t Camera2Client::startPreviewL(Parameters ¶ms, bool restart) { |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 595 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 596 | status_t res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 597 | if (params.state >= Parameters::PREVIEW && !restart) { |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 598 | ALOGE("%s: Can't start preview in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 599 | __FUNCTION__, |
| 600 | Parameters::getStateName(params.state)); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 601 | return INVALID_OPERATION; |
| 602 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 603 | |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 604 | if (mPreviewWindow == 0) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 605 | params.state = Parameters::WAITING_FOR_PREVIEW_WINDOW; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 606 | return OK; |
| 607 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 608 | params.state = Parameters::STOPPED; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 609 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 610 | res = updatePreviewStream(params); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 611 | if (res != OK) { |
| 612 | ALOGE("%s: Camera %d: Unable to update preview stream: %s (%d)", |
| 613 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 614 | return res; |
| 615 | } |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 616 | bool callbacksEnabled = params.previewCallbackFlags & |
| 617 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK; |
| 618 | if (callbacksEnabled) { |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 619 | res = mCallbackProcessor->updateStream(params); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 620 | if (res != OK) { |
| 621 | ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)", |
| 622 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 623 | return res; |
| 624 | } |
| 625 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 626 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 627 | if (mPreviewRequest.entryCount() == 0) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 628 | res = updatePreviewRequest(params); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 629 | if (res != OK) { |
| 630 | ALOGE("%s: Camera %d: Unable to create preview request: %s (%d)", |
| 631 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 632 | return res; |
| 633 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 636 | if (callbacksEnabled) { |
| 637 | uint8_t outputStreams[2] = |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 638 | { mPreviewStreamId, mCallbackProcessor->getStreamId() }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 639 | res = mPreviewRequest.update( |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 640 | ANDROID_REQUEST_OUTPUT_STREAMS, |
| 641 | outputStreams, 2); |
| 642 | } else { |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 643 | uint8_t outputStreams[1] = { mPreviewStreamId }; |
| 644 | res = mPreviewRequest.update( |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 645 | ANDROID_REQUEST_OUTPUT_STREAMS, |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 646 | outputStreams, 1); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 647 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 648 | if (res != OK) { |
| 649 | ALOGE("%s: Camera %d: Unable to set up preview request: %s (%d)", |
| 650 | __FUNCTION__, mCameraId, strerror(-res), res); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 651 | return res; |
| 652 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 653 | res = mPreviewRequest.sort(); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 654 | if (res != OK) { |
| 655 | ALOGE("%s: Camera %d: Error sorting preview request: %s (%d)", |
| 656 | __FUNCTION__, mCameraId, strerror(-res), res); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 657 | return res; |
| 658 | } |
| 659 | |
| 660 | res = mDevice->setStreamingRequest(mPreviewRequest); |
| 661 | if (res != OK) { |
Eino-Ville Talvala | bd47b7b | 2012-06-07 10:34:20 -0700 | [diff] [blame] | 662 | ALOGE("%s: Camera %d: Unable to set preview request to start preview: " |
| 663 | "%s (%d)", |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 664 | __FUNCTION__, mCameraId, strerror(-res), res); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 665 | return res; |
| 666 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 667 | params.state = Parameters::PREVIEW; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 668 | |
| 669 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | void Camera2Client::stopPreview() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 673 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 674 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 675 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 676 | status_t res; |
| 677 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 678 | stopPreviewL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 681 | void Camera2Client::stopPreviewL() { |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 682 | ATRACE_CALL(); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 683 | Parameters::State state; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 684 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 685 | SharedParameters::Lock l(mParameters); |
| 686 | state = l.mParameters.state; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | switch (state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 690 | case Parameters::DISCONNECTED: |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 691 | ALOGE("%s: Camera %d: Call before initialized", |
| 692 | __FUNCTION__, mCameraId); |
| 693 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 694 | case Parameters::STOPPED: |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 695 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 696 | case Parameters::STILL_CAPTURE: |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 697 | ALOGE("%s: Camera %d: Cannot stop preview during still capture.", |
| 698 | __FUNCTION__, mCameraId); |
| 699 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 700 | case Parameters::RECORD: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 701 | // no break - identical to preview |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 702 | case Parameters::PREVIEW: |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 703 | mDevice->clearStreamingRequest(); |
Eino-Ville Talvala | 2267106 | 2012-07-20 18:30:37 -0700 | [diff] [blame] | 704 | mDevice->waitUntilDrained(); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 705 | // no break |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 706 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: { |
| 707 | SharedParameters::Lock l(mParameters); |
| 708 | l.mParameters.state = Parameters::STOPPED; |
| 709 | commandStopFaceDetectionL(l.mParameters); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 710 | break; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 711 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 712 | default: |
| 713 | ALOGE("%s: Camera %d: Unknown state %d", __FUNCTION__, mCameraId, |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 714 | state); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 715 | } |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | bool Camera2Client::previewEnabled() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 719 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 720 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 721 | status_t res; |
| 722 | if ( (res = checkPid(__FUNCTION__) ) != OK) return false; |
| 723 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 724 | SharedParameters::Lock l(mParameters); |
| 725 | return l.mParameters.state == Parameters::PREVIEW; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | status_t Camera2Client::storeMetaDataInBuffers(bool enabled) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 729 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 730 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 731 | status_t res; |
| 732 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 733 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 734 | SharedParameters::Lock l(mParameters); |
| 735 | switch (l.mParameters.state) { |
| 736 | case Parameters::RECORD: |
| 737 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 738 | ALOGE("%s: Camera %d: Can't be called in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 739 | __FUNCTION__, mCameraId, |
| 740 | Parameters::getStateName(l.mParameters.state)); |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 741 | return INVALID_OPERATION; |
| 742 | default: |
| 743 | // OK |
| 744 | break; |
| 745 | } |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 746 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 747 | l.mParameters.storeMetadataInBuffers = enabled; |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 748 | |
| 749 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | status_t Camera2Client::startRecording() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 753 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 754 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 755 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 756 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 757 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 758 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 759 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 760 | return startRecordingL(l.mParameters, false); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | status_t Camera2Client::startRecordingL(Parameters ¶ms, bool restart) { |
| 764 | status_t res; |
| 765 | switch (params.state) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 766 | case Parameters::STOPPED: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 767 | res = startPreviewL(params, false); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 768 | if (res != OK) return res; |
| 769 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 770 | case Parameters::PREVIEW: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 771 | // Ready to go |
| 772 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 773 | case Parameters::RECORD: |
| 774 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 775 | // OK to call this when recording is already on, just skip unless |
| 776 | // we're looking to restart |
| 777 | if (!restart) return OK; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 778 | break; |
| 779 | default: |
| 780 | ALOGE("%s: Camera %d: Can't start recording in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 781 | __FUNCTION__, mCameraId, |
| 782 | Parameters::getStateName(params.state)); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 783 | return INVALID_OPERATION; |
| 784 | }; |
| 785 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 786 | if (!params.storeMetadataInBuffers) { |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 787 | ALOGE("%s: Camera %d: Recording only supported in metadata mode, but " |
| 788 | "non-metadata recording mode requested!", __FUNCTION__, |
| 789 | mCameraId); |
| 790 | return INVALID_OPERATION; |
| 791 | } |
| 792 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 793 | res = updateRecordingStream(params); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 794 | if (res != OK) { |
| 795 | ALOGE("%s: Camera %d: Unable to update recording stream: %s (%d)", |
| 796 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 797 | return res; |
| 798 | } |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 799 | bool callbacksEnabled = params.previewCallbackFlags & |
| 800 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK; |
| 801 | if (callbacksEnabled) { |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 802 | res = mCallbackProcessor->updateStream(params); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 803 | if (res != OK) { |
| 804 | ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)", |
| 805 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 806 | return res; |
| 807 | } |
| 808 | } |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 809 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 810 | if (mRecordingRequest.entryCount() == 0) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 811 | res = updateRecordingRequest(params); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 812 | if (res != OK) { |
| 813 | ALOGE("%s: Camera %d: Unable to create recording request: %s (%d)", |
| 814 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 815 | return res; |
| 816 | } |
| 817 | } |
| 818 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 819 | if (callbacksEnabled) { |
| 820 | uint8_t outputStreams[3] = |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 821 | { mPreviewStreamId, mRecordingStreamId, |
| 822 | mCallbackProcessor->getStreamId() }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 823 | res = mRecordingRequest.update( |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 824 | ANDROID_REQUEST_OUTPUT_STREAMS, |
| 825 | outputStreams, 3); |
| 826 | } else { |
| 827 | uint8_t outputStreams[2] = { mPreviewStreamId, mRecordingStreamId }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 828 | res = mRecordingRequest.update( |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 829 | ANDROID_REQUEST_OUTPUT_STREAMS, |
| 830 | outputStreams, 2); |
| 831 | } |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 832 | if (res != OK) { |
| 833 | ALOGE("%s: Camera %d: Unable to set up recording request: %s (%d)", |
| 834 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 835 | return res; |
| 836 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 837 | res = mRecordingRequest.sort(); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 838 | if (res != OK) { |
| 839 | ALOGE("%s: Camera %d: Error sorting recording request: %s (%d)", |
| 840 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 841 | return res; |
| 842 | } |
| 843 | |
| 844 | res = mDevice->setStreamingRequest(mRecordingRequest); |
| 845 | if (res != OK) { |
| 846 | ALOGE("%s: Camera %d: Unable to set recording request to start " |
| 847 | "recording: %s (%d)", __FUNCTION__, mCameraId, |
| 848 | strerror(-res), res); |
| 849 | return res; |
| 850 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 851 | if (params.state < Parameters::RECORD) { |
| 852 | params.state = Parameters::RECORD; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 853 | } |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 854 | |
| 855 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | void Camera2Client::stopRecording() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 859 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 860 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 861 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 862 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 863 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 864 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 865 | if ( (res = checkPid(__FUNCTION__) ) != OK) return; |
| 866 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 867 | switch (l.mParameters.state) { |
| 868 | case Parameters::RECORD: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 869 | // OK to stop |
| 870 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 871 | case Parameters::STOPPED: |
| 872 | case Parameters::PREVIEW: |
| 873 | case Parameters::STILL_CAPTURE: |
| 874 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 875 | default: |
| 876 | ALOGE("%s: Camera %d: Can't stop recording in state %s", |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 877 | __FUNCTION__, mCameraId, |
| 878 | Parameters::getStateName(l.mParameters.state)); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 879 | return; |
| 880 | }; |
| 881 | |
| 882 | // Back to preview. Since record can only be reached through preview, |
| 883 | // all preview stream setup should be up to date. |
| 884 | res = mDevice->setStreamingRequest(mPreviewRequest); |
| 885 | if (res != OK) { |
| 886 | ALOGE("%s: Camera %d: Unable to switch back to preview request: " |
| 887 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | // TODO: Should recording heap be freed? Can't do it yet since requests |
| 892 | // could still be in flight. |
| 893 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 894 | l.mParameters.state = Parameters::PREVIEW; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | bool Camera2Client::recordingEnabled() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 898 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 899 | Mutex::Autolock icl(mICameraLock); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 900 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 901 | if ( checkPid(__FUNCTION__) != OK) return false; |
| 902 | |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 903 | return recordingEnabledL(); |
| 904 | } |
| 905 | |
| 906 | bool Camera2Client::recordingEnabledL() { |
| 907 | ATRACE_CALL(); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 908 | SharedParameters::Lock l(mParameters); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 909 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 910 | return (l.mParameters.state == Parameters::RECORD |
| 911 | || l.mParameters.state == Parameters::VIDEO_SNAPSHOT); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 915 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 916 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 917 | status_t res; |
| 918 | if ( checkPid(__FUNCTION__) != OK) return; |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 919 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 920 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 921 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 922 | // Make sure this is for the current heap |
| 923 | ssize_t offset; |
| 924 | size_t size; |
| 925 | sp<IMemoryHeap> heap = mem->getMemory(&offset, &size); |
| 926 | if (heap->getHeapID() != mRecordingHeap->mHeap->getHeapID()) { |
| 927 | ALOGW("%s: Camera %d: Mismatched heap ID, ignoring release " |
| 928 | "(got %x, expected %x)", __FUNCTION__, mCameraId, |
| 929 | heap->getHeapID(), mRecordingHeap->mHeap->getHeapID()); |
| 930 | return; |
| 931 | } |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 932 | uint8_t *data = (uint8_t*)heap->getBase() + offset; |
| 933 | uint32_t type = *(uint32_t*)data; |
| 934 | if (type != kMetadataBufferTypeGrallocSource) { |
| 935 | ALOGE("%s: Camera %d: Recording frame type invalid (got %x, expected %x)", |
| 936 | __FUNCTION__, mCameraId, type, kMetadataBufferTypeGrallocSource); |
| 937 | return; |
| 938 | } |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 939 | |
| 940 | // Release the buffer back to the recording queue |
| 941 | |
| 942 | buffer_handle_t imgHandle = *(buffer_handle_t*)(data + 4); |
| 943 | |
| 944 | size_t itemIndex; |
| 945 | for (itemIndex = 0; itemIndex < mRecordingBuffers.size(); itemIndex++) { |
| 946 | const BufferItemConsumer::BufferItem item = mRecordingBuffers[itemIndex]; |
| 947 | if (item.mBuf != BufferItemConsumer::INVALID_BUFFER_SLOT && |
| 948 | item.mGraphicBuffer->handle == imgHandle) { |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | if (itemIndex == mRecordingBuffers.size()) { |
| 953 | ALOGE("%s: Camera %d: Can't find buffer_handle_t %p in list of " |
| 954 | "outstanding buffers", __FUNCTION__, mCameraId, imgHandle); |
| 955 | return; |
| 956 | } |
| 957 | |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 958 | ALOGV("%s: Camera %d: Freeing buffer_handle_t %p", __FUNCTION__, mCameraId, |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 959 | imgHandle); |
| 960 | |
| 961 | res = mRecordingConsumer->releaseBuffer(mRecordingBuffers[itemIndex]); |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 962 | if (res != OK) { |
| 963 | ALOGE("%s: Camera %d: Unable to free recording frame (buffer_handle_t: %p):" |
| 964 | "%s (%d)", |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 965 | __FUNCTION__, mCameraId, imgHandle, strerror(-res), res); |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 966 | return; |
| 967 | } |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 968 | mRecordingBuffers.replaceAt(itemIndex); |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 969 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 970 | mRecordingHeapFree++; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | status_t Camera2Client::autoFocus() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 974 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 975 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 976 | status_t res; |
| 977 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 978 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 979 | int triggerId; |
| 980 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 981 | SharedParameters::Lock l(mParameters); |
| 982 | l.mParameters.currentAfTriggerId = ++l.mParameters.afTriggerCounter; |
| 983 | triggerId = l.mParameters.currentAfTriggerId; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | mDevice->triggerAutofocus(triggerId); |
| 987 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 988 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | status_t Camera2Client::cancelAutoFocus() { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 992 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 993 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 994 | status_t res; |
| 995 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 996 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 997 | int triggerId; |
| 998 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 999 | SharedParameters::Lock l(mParameters); |
| 1000 | triggerId = ++l.mParameters.afTriggerCounter; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | mDevice->triggerCancelAutofocus(triggerId); |
| 1004 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1005 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | status_t Camera2Client::takePicture(int msgType) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1009 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1010 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1011 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1012 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1013 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1014 | SharedParameters::Lock l(mParameters); |
| 1015 | switch (l.mParameters.state) { |
| 1016 | case Parameters::DISCONNECTED: |
| 1017 | case Parameters::STOPPED: |
| 1018 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1019 | ALOGE("%s: Camera %d: Cannot take picture without preview enabled", |
| 1020 | __FUNCTION__, mCameraId); |
| 1021 | return INVALID_OPERATION; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1022 | case Parameters::PREVIEW: |
| 1023 | case Parameters::RECORD: |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1024 | // Good to go for takePicture |
| 1025 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1026 | case Parameters::STILL_CAPTURE: |
| 1027 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1028 | ALOGE("%s: Camera %d: Already taking a picture", |
| 1029 | __FUNCTION__, mCameraId); |
| 1030 | return INVALID_OPERATION; |
| 1031 | } |
| 1032 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1033 | ALOGV("%s: Camera %d: Starting picture capture", __FUNCTION__, mCameraId); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1034 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 1035 | res = mCaptureProcessor->updateStream(l.mParameters); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1036 | if (res != OK) { |
| 1037 | ALOGE("%s: Camera %d: Can't set up still image stream: %s (%d)", |
| 1038 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1039 | return res; |
| 1040 | } |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1041 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1042 | if (mCaptureRequest.entryCount() == 0) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1043 | res = updateCaptureRequest(l.mParameters); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 1044 | if (res != OK) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1045 | ALOGE("%s: Camera %d: Can't create still image capture request: " |
| 1046 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 1047 | return res; |
| 1048 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1051 | bool callbacksEnabled = l.mParameters.previewCallbackFlags & |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1052 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1053 | bool recordingEnabled = (l.mParameters.state == Parameters::RECORD); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1054 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 1055 | int captureStreamId = mCaptureProcessor->getStreamId(); |
| 1056 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1057 | int streamSwitch = (callbacksEnabled ? 0x2 : 0x0) + |
| 1058 | (recordingEnabled ? 0x1 : 0x0); |
| 1059 | switch ( streamSwitch ) { |
| 1060 | case 0: { // No recording, callbacks |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 1061 | uint8_t streamIds[2] = { |
| 1062 | mPreviewStreamId, |
| 1063 | captureStreamId |
| 1064 | }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1065 | res = mCaptureRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, |
| 1066 | streamIds, 2); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1067 | break; |
| 1068 | } |
| 1069 | case 1: { // Recording |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 1070 | uint8_t streamIds[3] = { |
| 1071 | mPreviewStreamId, |
| 1072 | mRecordingStreamId, |
| 1073 | captureStreamId |
| 1074 | }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1075 | res = mCaptureRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, |
| 1076 | streamIds, 3); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1077 | break; |
| 1078 | } |
| 1079 | case 2: { // Callbacks |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 1080 | uint8_t streamIds[3] = { |
| 1081 | mPreviewStreamId, |
| 1082 | mCallbackProcessor->getStreamId(), |
| 1083 | captureStreamId |
| 1084 | }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1085 | res = mCaptureRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, |
| 1086 | streamIds, 3); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1087 | break; |
| 1088 | } |
| 1089 | case 3: { // Both |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame^] | 1090 | uint8_t streamIds[4] = { |
| 1091 | mPreviewStreamId, |
| 1092 | mCallbackProcessor->getStreamId(), |
| 1093 | mRecordingStreamId, |
| 1094 | captureStreamId |
| 1095 | }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1096 | res = mCaptureRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, |
| 1097 | streamIds, 4); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1098 | break; |
| 1099 | } |
| 1100 | }; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1101 | if (res != OK) { |
| 1102 | ALOGE("%s: Camera %d: Unable to set up still image capture request: " |
| 1103 | "%s (%d)", |
| 1104 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1105 | return res; |
| 1106 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1107 | res = mCaptureRequest.sort(); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1108 | if (res != OK) { |
| 1109 | ALOGE("%s: Camera %d: Unable to sort capture request: %s (%d)", |
| 1110 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1111 | return res; |
| 1112 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1113 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1114 | CameraMetadata captureCopy = mCaptureRequest; |
| 1115 | if (captureCopy.entryCount() == 0) { |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1116 | ALOGE("%s: Camera %d: Unable to copy capture request for HAL device", |
| 1117 | __FUNCTION__, mCameraId); |
| 1118 | return NO_MEMORY; |
| 1119 | } |
| 1120 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1121 | if (l.mParameters.state == Parameters::PREVIEW) { |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1122 | res = mDevice->clearStreamingRequest(); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1123 | if (res != OK) { |
| 1124 | ALOGE("%s: Camera %d: Unable to stop preview for still capture: " |
| 1125 | "%s (%d)", |
| 1126 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1127 | return res; |
| 1128 | } |
| 1129 | } |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1130 | // TODO: Capture should be atomic with setStreamingRequest here |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1131 | res = mDevice->capture(captureCopy); |
| 1132 | if (res != OK) { |
| 1133 | ALOGE("%s: Camera %d: Unable to submit still image capture request: " |
| 1134 | "%s (%d)", |
| 1135 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1136 | return res; |
| 1137 | } |
| 1138 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1139 | switch (l.mParameters.state) { |
| 1140 | case Parameters::PREVIEW: |
| 1141 | l.mParameters.state = Parameters::STILL_CAPTURE; |
| 1142 | res = commandStopFaceDetectionL(l.mParameters); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1143 | if (res != OK) { |
| 1144 | ALOGE("%s: Camera %d: Unable to stop face detection for still capture", |
| 1145 | __FUNCTION__, mCameraId); |
| 1146 | return res; |
| 1147 | } |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1148 | break; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1149 | case Parameters::RECORD: |
| 1150 | l.mParameters.state = Parameters::VIDEO_SNAPSHOT; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | default: |
| 1153 | ALOGE("%s: Camera %d: Unknown state for still capture!", |
| 1154 | __FUNCTION__, mCameraId); |
| 1155 | return INVALID_OPERATION; |
| 1156 | } |
| 1157 | |
| 1158 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | status_t Camera2Client::setParameters(const String8& params) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1162 | ATRACE_CALL(); |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 1163 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1164 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1165 | status_t res; |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1166 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 1167 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1168 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1169 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1170 | res = l.mParameters.set(params); |
| 1171 | if (res != OK) return res; |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 1172 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1173 | res = updateRequests(l.mParameters); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1174 | |
| 1175 | return res; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1176 | } |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 1177 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1178 | String8 Camera2Client::getParameters() const { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1179 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1180 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1181 | if ( checkPid(__FUNCTION__) != OK) return String8(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1182 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1183 | SharedParameters::ReadLock l(mParameters); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1184 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1185 | // TODO: Deal with focus distances |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1186 | return l.mParameters.paramsFlattened; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | 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] | 1190 | ATRACE_CALL(); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 1191 | Mutex::Autolock icl(mICameraLock); |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 1192 | status_t res; |
| 1193 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1194 | |
| 1195 | ALOGV("%s: Camera %d: Command %d (%d, %d)", __FUNCTION__, mCameraId, |
| 1196 | cmd, arg1, arg2); |
| 1197 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1198 | switch (cmd) { |
| 1199 | case CAMERA_CMD_START_SMOOTH_ZOOM: |
| 1200 | return commandStartSmoothZoomL(); |
| 1201 | case CAMERA_CMD_STOP_SMOOTH_ZOOM: |
| 1202 | return commandStopSmoothZoomL(); |
| 1203 | case CAMERA_CMD_SET_DISPLAY_ORIENTATION: |
| 1204 | return commandSetDisplayOrientationL(arg1); |
| 1205 | case CAMERA_CMD_ENABLE_SHUTTER_SOUND: |
| 1206 | return commandEnableShutterSoundL(arg1 == 1); |
| 1207 | case CAMERA_CMD_PLAY_RECORDING_SOUND: |
| 1208 | return commandPlayRecordingSoundL(); |
| 1209 | case CAMERA_CMD_START_FACE_DETECTION: |
| 1210 | return commandStartFaceDetectionL(arg1); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1211 | case CAMERA_CMD_STOP_FACE_DETECTION: { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1212 | SharedParameters::Lock l(mParameters); |
| 1213 | return commandStopFaceDetectionL(l.mParameters); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1214 | } |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1215 | case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG: |
| 1216 | return commandEnableFocusMoveMsgL(arg1 == 1); |
| 1217 | case CAMERA_CMD_PING: |
| 1218 | return commandPingL(); |
| 1219 | case CAMERA_CMD_SET_VIDEO_BUFFER_COUNT: |
| 1220 | return commandSetVideoBufferCountL(arg1); |
| 1221 | default: |
| 1222 | ALOGE("%s: Unknown command %d (arguments %d, %d)", |
| 1223 | __FUNCTION__, cmd, arg1, arg2); |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1224 | return BAD_VALUE; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1225 | } |
| 1226 | } |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1227 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1228 | status_t Camera2Client::commandStartSmoothZoomL() { |
| 1229 | ALOGE("%s: Unimplemented!", __FUNCTION__); |
| 1230 | return OK; |
| 1231 | } |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1232 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1233 | status_t Camera2Client::commandStopSmoothZoomL() { |
| 1234 | ALOGE("%s: Unimplemented!", __FUNCTION__); |
| 1235 | return OK; |
| 1236 | } |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1237 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1238 | status_t Camera2Client::commandSetDisplayOrientationL(int degrees) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1239 | int transform = Parameters::degToTransform(degrees, |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1240 | mCameraFacing == CAMERA_FACING_FRONT); |
| 1241 | if (transform == -1) { |
| 1242 | ALOGE("%s: Camera %d: Error setting %d as display orientation value", |
| 1243 | __FUNCTION__, mCameraId, degrees); |
| 1244 | return BAD_VALUE; |
| 1245 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1246 | SharedParameters::Lock l(mParameters); |
| 1247 | if (transform != l.mParameters.previewTransform && |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1248 | mPreviewStreamId != NO_STREAM) { |
| 1249 | mDevice->setStreamTransform(mPreviewStreamId, transform); |
| 1250 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1251 | l.mParameters.previewTransform = transform; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1252 | return OK; |
| 1253 | } |
| 1254 | |
| 1255 | status_t Camera2Client::commandEnableShutterSoundL(bool enable) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1256 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1257 | if (enable) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1258 | l.mParameters.playShutterSound = true; |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1259 | return OK; |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1262 | // Disabling shutter sound may not be allowed. In that case only |
| 1263 | // allow the mediaserver process to disable the sound. |
| 1264 | char value[PROPERTY_VALUE_MAX]; |
| 1265 | property_get("ro.camera.sound.forced", value, "0"); |
| 1266 | if (strncmp(value, "0", 2) != 0) { |
| 1267 | // Disabling shutter sound is not allowed. Deny if the current |
| 1268 | // process is not mediaserver. |
| 1269 | if (getCallingPid() != getpid()) { |
| 1270 | ALOGE("Failed to disable shutter sound. Permission denied (pid %d)", |
| 1271 | getCallingPid()); |
| 1272 | return PERMISSION_DENIED; |
| 1273 | } |
| 1274 | } |
| 1275 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1276 | l.mParameters.playShutterSound = false; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1277 | return OK; |
| 1278 | } |
| 1279 | |
| 1280 | status_t Camera2Client::commandPlayRecordingSoundL() { |
| 1281 | mCameraService->playSound(CameraService::SOUND_RECORDING); |
| 1282 | return OK; |
| 1283 | } |
| 1284 | |
| 1285 | status_t Camera2Client::commandStartFaceDetectionL(int type) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1286 | ALOGV("%s: Camera %d: Starting face detection", |
| 1287 | __FUNCTION__, mCameraId); |
| 1288 | status_t res; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1289 | SharedParameters::Lock l(mParameters); |
| 1290 | switch (l.mParameters.state) { |
| 1291 | case Parameters::DISCONNECTED: |
| 1292 | case Parameters::STOPPED: |
| 1293 | case Parameters::WAITING_FOR_PREVIEW_WINDOW: |
| 1294 | case Parameters::STILL_CAPTURE: |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1295 | ALOGE("%s: Camera %d: Cannot start face detection without preview active", |
| 1296 | __FUNCTION__, mCameraId); |
| 1297 | return INVALID_OPERATION; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1298 | case Parameters::PREVIEW: |
| 1299 | case Parameters::RECORD: |
| 1300 | case Parameters::VIDEO_SNAPSHOT: |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1301 | // Good to go for starting face detect |
| 1302 | break; |
| 1303 | } |
| 1304 | // Ignoring type |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1305 | if (l.mParameters.fastInfo.bestFaceDetectMode == |
| 1306 | ANDROID_STATS_FACE_DETECTION_OFF) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1307 | ALOGE("%s: Camera %d: Face detection not supported", |
| 1308 | __FUNCTION__, mCameraId); |
| 1309 | return INVALID_OPERATION; |
| 1310 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1311 | if (l.mParameters.enableFaceDetect) return OK; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1312 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1313 | l.mParameters.enableFaceDetect = true; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1314 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1315 | res = updateRequests(l.mParameters); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1316 | |
| 1317 | return res; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1320 | status_t Camera2Client::commandStopFaceDetectionL(Parameters ¶ms) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1321 | status_t res = OK; |
| 1322 | ALOGV("%s: Camera %d: Stopping face detection", |
| 1323 | __FUNCTION__, mCameraId); |
| 1324 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1325 | if (!params.enableFaceDetect) return OK; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1326 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1327 | params.enableFaceDetect = false; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1328 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1329 | if (params.state == Parameters::PREVIEW |
| 1330 | || params.state == Parameters::RECORD |
| 1331 | || params.state == Parameters::VIDEO_SNAPSHOT) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1332 | res = updateRequests(params); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | return res; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | status_t Camera2Client::commandEnableFocusMoveMsgL(bool enable) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1339 | SharedParameters::Lock l(mParameters); |
| 1340 | l.mParameters.enableFocusMoveMessages = enable; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1341 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1342 | return OK; |
| 1343 | } |
| 1344 | |
| 1345 | status_t Camera2Client::commandPingL() { |
| 1346 | // Always ping back if access is proper and device is alive |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1347 | SharedParameters::Lock l(mParameters); |
| 1348 | if (l.mParameters.state != Parameters::DISCONNECTED) { |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1349 | return OK; |
| 1350 | } else { |
| 1351 | return NO_INIT; |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | status_t Camera2Client::commandSetVideoBufferCountL(size_t count) { |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 1356 | if (recordingEnabledL()) { |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 1357 | ALOGE("%s: Camera %d: Error setting video buffer count after " |
| 1358 | "recording was started", __FUNCTION__, mCameraId); |
| 1359 | return INVALID_OPERATION; |
| 1360 | } |
| 1361 | |
| 1362 | // 32 is the current upper limit on the video buffer count for BufferQueue |
| 1363 | if (count > 32) { |
| 1364 | ALOGE("%s: Camera %d: Error setting %d as video buffer count value", |
| 1365 | __FUNCTION__, mCameraId, count); |
| 1366 | return BAD_VALUE; |
| 1367 | } |
| 1368 | |
| 1369 | // Need to reallocate memory for heap |
| 1370 | if (mRecordingHeapCount != count) { |
| 1371 | if (mRecordingHeap != 0) { |
| 1372 | mRecordingHeap.clear(); |
| 1373 | mRecordingHeap = NULL; |
| 1374 | } |
| 1375 | mRecordingHeapCount = count; |
| 1376 | } |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1377 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1378 | return OK; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1381 | /** Device-related methods */ |
| 1382 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1383 | void Camera2Client::notifyError(int errorCode, int arg1, int arg2) { |
| 1384 | ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, arg1, arg2); |
| 1385 | } |
| 1386 | |
| 1387 | void Camera2Client::notifyShutter(int frameNumber, nsecs_t timestamp) { |
| 1388 | ALOGV("%s: Shutter notification for frame %d at time %lld", __FUNCTION__, |
| 1389 | frameNumber, timestamp); |
| 1390 | } |
| 1391 | |
| 1392 | void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { |
| 1393 | ALOGV("%s: Autofocus state now %d, last trigger %d", |
| 1394 | __FUNCTION__, newState, triggerId); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1395 | bool sendCompletedMessage = false; |
| 1396 | bool sendMovingMessage = false; |
| 1397 | |
| 1398 | bool success = false; |
| 1399 | bool afInMotion = false; |
| 1400 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1401 | SharedParameters::Lock l(mParameters); |
| 1402 | switch (l.mParameters.focusMode) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1403 | case Parameters::FOCUS_MODE_AUTO: |
| 1404 | case Parameters::FOCUS_MODE_MACRO: |
| 1405 | // Don't send notifications upstream if they're not for the current AF |
| 1406 | // trigger. For example, if cancel was called in between, or if we |
| 1407 | // already sent a notification about this AF call. |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1408 | if (triggerId != l.mParameters.currentAfTriggerId) break; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1409 | switch (newState) { |
| 1410 | case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED: |
| 1411 | success = true; |
| 1412 | // no break |
| 1413 | case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: |
| 1414 | sendCompletedMessage = true; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1415 | l.mParameters.currentAfTriggerId = -1; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | case ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN: |
| 1418 | // Just starting focusing, ignore |
| 1419 | break; |
| 1420 | case ANDROID_CONTROL_AF_STATE_INACTIVE: |
| 1421 | case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN: |
| 1422 | case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED: |
| 1423 | default: |
| 1424 | // Unexpected in AUTO/MACRO mode |
| 1425 | ALOGE("%s: Unexpected AF state transition in AUTO/MACRO mode: %d", |
| 1426 | __FUNCTION__, newState); |
| 1427 | break; |
| 1428 | } |
| 1429 | break; |
| 1430 | case Parameters::FOCUS_MODE_CONTINUOUS_VIDEO: |
| 1431 | case Parameters::FOCUS_MODE_CONTINUOUS_PICTURE: |
| 1432 | switch (newState) { |
| 1433 | case ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED: |
| 1434 | success = true; |
| 1435 | // no break |
| 1436 | case ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: |
| 1437 | // Don't send notifications upstream if they're not for |
| 1438 | // the current AF trigger. For example, if cancel was |
| 1439 | // called in between, or if we already sent a |
| 1440 | // notification about this AF call. |
| 1441 | // Send both a 'AF done' callback and a 'AF move' callback |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1442 | if (triggerId != l.mParameters.currentAfTriggerId) break; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1443 | sendCompletedMessage = true; |
| 1444 | afInMotion = false; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1445 | if (l.mParameters.enableFocusMoveMessages && |
| 1446 | l.mParameters.afInMotion) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1447 | sendMovingMessage = true; |
| 1448 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1449 | l.mParameters.currentAfTriggerId = -1; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1450 | break; |
| 1451 | case ANDROID_CONTROL_AF_STATE_INACTIVE: |
| 1452 | // Cancel was called, or we switched state; care if |
| 1453 | // currently moving |
| 1454 | afInMotion = false; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1455 | if (l.mParameters.enableFocusMoveMessages && |
| 1456 | l.mParameters.afInMotion) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1457 | sendMovingMessage = true; |
| 1458 | } |
| 1459 | break; |
| 1460 | case ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN: |
| 1461 | // Start passive scan, inform upstream |
| 1462 | afInMotion = true; |
| 1463 | // no break |
| 1464 | case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED: |
| 1465 | // Stop passive scan, inform upstream |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1466 | if (l.mParameters.enableFocusMoveMessages) { |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1467 | sendMovingMessage = true; |
| 1468 | } |
| 1469 | break; |
| 1470 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1471 | l.mParameters.afInMotion = afInMotion; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1472 | break; |
| 1473 | case Parameters::FOCUS_MODE_EDOF: |
| 1474 | case Parameters::FOCUS_MODE_INFINITY: |
| 1475 | case Parameters::FOCUS_MODE_FIXED: |
| 1476 | default: |
| 1477 | if (newState != ANDROID_CONTROL_AF_STATE_INACTIVE) { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1478 | ALOGE("%s: Unexpected AF state change %d " |
| 1479 | "(ID %d) in focus mode %d", |
| 1480 | __FUNCTION__, newState, triggerId, |
| 1481 | l.mParameters.focusMode); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | } |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1485 | if (sendMovingMessage) { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1486 | SharedCameraClient::Lock l(mSharedCameraClient); |
| 1487 | if (l.mCameraClient != 0) { |
| 1488 | l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS_MOVE, |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1489 | afInMotion ? 1 : 0, 0); |
| 1490 | } |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 1491 | } |
Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 1492 | if (sendCompletedMessage) { |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1493 | SharedCameraClient::Lock l(mSharedCameraClient); |
| 1494 | if (l.mCameraClient != 0) { |
| 1495 | l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, |
| 1496 | success ? 1 : 0, 0); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1497 | } |
Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 1498 | } |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | void Camera2Client::notifyAutoExposure(uint8_t newState, int triggerId) { |
| 1502 | ALOGV("%s: Autoexposure state now %d, last trigger %d", |
| 1503 | __FUNCTION__, newState, triggerId); |
| 1504 | } |
| 1505 | |
| 1506 | void Camera2Client::notifyAutoWhitebalance(uint8_t newState, int triggerId) { |
| 1507 | ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", |
| 1508 | __FUNCTION__, newState, triggerId); |
| 1509 | } |
| 1510 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1511 | int Camera2Client::getCameraId() { |
| 1512 | return mCameraId; |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1515 | const sp<Camera2Device>& Camera2Client::getCameraDevice() { |
| 1516 | return mDevice; |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1519 | camera2::SharedParameters& Camera2Client::getParameters() { |
| 1520 | return mParameters; |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1523 | Camera2Client::SharedCameraClient::Lock::Lock(SharedCameraClient &client): |
| 1524 | mCameraClient(client.mCameraClient), |
| 1525 | mSharedClient(client) { |
| 1526 | mSharedClient.mCameraClientLock.lock(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1529 | Camera2Client::SharedCameraClient::Lock::~Lock() { |
| 1530 | mSharedClient.mCameraClientLock.unlock(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 1533 | Camera2Client::SharedCameraClient::SharedCameraClient(const sp<ICameraClient>&client): |
| 1534 | mCameraClient(client) { |
| 1535 | } |
| 1536 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1537 | Camera2Client::SharedCameraClient& Camera2Client::SharedCameraClient::operator=( |
| 1538 | const sp<ICameraClient>&client) { |
| 1539 | Mutex::Autolock l(mCameraClientLock); |
| 1540 | mCameraClient = client; |
| 1541 | return *this; |
| 1542 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1543 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1544 | void Camera2Client::SharedCameraClient::clear() { |
| 1545 | Mutex::Autolock l(mCameraClientLock); |
| 1546 | mCameraClient.clear(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1549 | void Camera2Client::onRecordingFrameAvailable() { |
| 1550 | ATRACE_CALL(); |
| 1551 | status_t res; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1552 | sp<Camera2Heap> recordingHeap; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1553 | size_t heapIdx = 0; |
| 1554 | nsecs_t timestamp; |
| 1555 | { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1556 | SharedParameters::Lock l(mParameters); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1557 | |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1558 | BufferItemConsumer::BufferItem imgBuffer; |
| 1559 | res = mRecordingConsumer->acquireBuffer(&imgBuffer); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1560 | if (res != OK) { |
| 1561 | ALOGE("%s: Camera %d: Error receiving recording buffer: %s (%d)", |
| 1562 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1563 | return; |
| 1564 | } |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1565 | timestamp = imgBuffer.mTimestamp; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1566 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1567 | mRecordingFrameCount++; |
| 1568 | ALOGV("OnRecordingFrame: Frame %d", mRecordingFrameCount); |
| 1569 | |
| 1570 | // TODO: Signal errors here upstream |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1571 | if (l.mParameters.state != Parameters::RECORD && |
| 1572 | l.mParameters.state != Parameters::VIDEO_SNAPSHOT) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1573 | ALOGV("%s: Camera %d: Discarding recording image buffers received after " |
| 1574 | "recording done", |
| 1575 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1576 | mRecordingConsumer->releaseBuffer(imgBuffer); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1577 | return; |
| 1578 | } |
Eino-Ville Talvala | 898a9a9 | 2012-07-20 11:05:20 -0700 | [diff] [blame] | 1579 | |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 1580 | if (mRecordingHeap == 0) { |
| 1581 | const size_t bufferSize = 4 + sizeof(buffer_handle_t); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1582 | ALOGV("%s: Camera %d: Creating recording heap with %d buffers of " |
| 1583 | "size %d bytes", __FUNCTION__, mCameraId, |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1584 | mRecordingHeapCount, bufferSize); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1585 | |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1586 | mRecordingHeap = new Camera2Heap(bufferSize, mRecordingHeapCount, |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1587 | "Camera2Client::RecordingHeap"); |
| 1588 | if (mRecordingHeap->mHeap->getSize() == 0) { |
| 1589 | ALOGE("%s: Camera %d: Unable to allocate memory for recording", |
| 1590 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1591 | mRecordingConsumer->releaseBuffer(imgBuffer); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1592 | return; |
| 1593 | } |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1594 | for (size_t i = 0; i < mRecordingBuffers.size(); i++) { |
| 1595 | if (mRecordingBuffers[i].mBuf != |
| 1596 | BufferItemConsumer::INVALID_BUFFER_SLOT) { |
| 1597 | ALOGE("%s: Camera %d: Non-empty recording buffers list!", |
| 1598 | __FUNCTION__, mCameraId); |
| 1599 | } |
| 1600 | } |
| 1601 | mRecordingBuffers.clear(); |
| 1602 | mRecordingBuffers.setCapacity(mRecordingHeapCount); |
| 1603 | mRecordingBuffers.insertAt(0, mRecordingHeapCount); |
| 1604 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1605 | mRecordingHeapHead = 0; |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1606 | mRecordingHeapFree = mRecordingHeapCount; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1609 | if ( mRecordingHeapFree == 0) { |
| 1610 | ALOGE("%s: Camera %d: No free recording buffers, dropping frame", |
| 1611 | __FUNCTION__, mCameraId); |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1612 | mRecordingConsumer->releaseBuffer(imgBuffer); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1613 | return; |
| 1614 | } |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1615 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1616 | heapIdx = mRecordingHeapHead; |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 1617 | mRecordingHeapHead = (mRecordingHeapHead + 1) % mRecordingHeapCount; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1618 | mRecordingHeapFree--; |
| 1619 | |
| 1620 | ALOGV("%s: Camera %d: Timestamp %lld", |
| 1621 | __FUNCTION__, mCameraId, timestamp); |
| 1622 | |
| 1623 | ssize_t offset; |
| 1624 | size_t size; |
| 1625 | sp<IMemoryHeap> heap = |
| 1626 | mRecordingHeap->mBuffers[heapIdx]->getMemory(&offset, |
| 1627 | &size); |
| 1628 | |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 1629 | uint8_t *data = (uint8_t*)heap->getBase() + offset; |
| 1630 | uint32_t type = kMetadataBufferTypeGrallocSource; |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1631 | *((uint32_t*)data) = type; |
| 1632 | *((buffer_handle_t*)(data + 4)) = imgBuffer.mGraphicBuffer->handle; |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 1633 | ALOGV("%s: Camera %d: Sending out buffer_handle_t %p", |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1634 | __FUNCTION__, mCameraId, imgBuffer.mGraphicBuffer->handle); |
| 1635 | mRecordingBuffers.replaceAt(imgBuffer, heapIdx); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1636 | recordingHeap = mRecordingHeap; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1637 | } |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1638 | |
| 1639 | // Call outside locked parameters to allow re-entrancy from notification |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 1640 | SharedCameraClient::Lock l(mSharedCameraClient); |
| 1641 | if (l.mCameraClient != 0) { |
| 1642 | l.mCameraClient->dataCallbackTimestamp(timestamp, |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1643 | CAMERA_MSG_VIDEO_FRAME, |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1644 | recordingHeap->mBuffers[heapIdx]); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 1648 | /** Utility methods */ |
| 1649 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1650 | status_t Camera2Client::updateRequests(const Parameters ¶ms) { |
| 1651 | status_t res; |
| 1652 | |
| 1653 | res = updatePreviewRequest(params); |
| 1654 | if (res != OK) { |
| 1655 | ALOGE("%s: Camera %d: Unable to update preview request: %s (%d)", |
| 1656 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1657 | return res; |
| 1658 | } |
| 1659 | res = updateCaptureRequest(params); |
| 1660 | if (res != OK) { |
| 1661 | ALOGE("%s: Camera %d: Unable to update capture request: %s (%d)", |
| 1662 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1663 | return res; |
| 1664 | } |
| 1665 | |
| 1666 | res = updateRecordingRequest(params); |
| 1667 | if (res != OK) { |
| 1668 | ALOGE("%s: Camera %d: Unable to update recording request: %s (%d)", |
| 1669 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1670 | return res; |
| 1671 | } |
| 1672 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1673 | if (params.state == Parameters::PREVIEW) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1674 | res = mDevice->setStreamingRequest(mPreviewRequest); |
| 1675 | if (res != OK) { |
| 1676 | ALOGE("%s: Camera %d: Error streaming new preview request: %s (%d)", |
| 1677 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1678 | return res; |
| 1679 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1680 | } else if (params.state == Parameters::RECORD || |
| 1681 | params.state == Parameters::VIDEO_SNAPSHOT) { |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 1682 | res = mDevice->setStreamingRequest(mRecordingRequest); |
| 1683 | if (res != OK) { |
| 1684 | ALOGE("%s: Camera %d: Error streaming new record request: %s (%d)", |
| 1685 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1686 | return res; |
| 1687 | } |
| 1688 | } |
| 1689 | return res; |
| 1690 | } |
| 1691 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1692 | status_t Camera2Client::updatePreviewStream(const Parameters ¶ms) { |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1693 | ATRACE_CALL(); |
| 1694 | status_t res; |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1695 | |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1696 | if (mPreviewStreamId != NO_STREAM) { |
| 1697 | // Check if stream parameters have to change |
| 1698 | uint32_t currentWidth, currentHeight; |
| 1699 | res = mDevice->getStreamInfo(mPreviewStreamId, |
| 1700 | ¤tWidth, ¤tHeight, 0); |
| 1701 | if (res != OK) { |
| 1702 | ALOGE("%s: Camera %d: Error querying preview stream info: " |
| 1703 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1704 | return res; |
| 1705 | } |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1706 | if (currentWidth != (uint32_t)params.previewWidth || |
| 1707 | currentHeight != (uint32_t)params.previewHeight) { |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 1708 | ALOGV("%s: Camera %d: Preview size switch: %d x %d -> %d x %d", |
| 1709 | __FUNCTION__, mCameraId, currentWidth, currentHeight, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1710 | params.previewWidth, params.previewHeight); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1711 | res = mDevice->waitUntilDrained(); |
| 1712 | if (res != OK) { |
| 1713 | ALOGE("%s: Camera %d: Error waiting for preview to drain: " |
| 1714 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1715 | return res; |
| 1716 | } |
| 1717 | res = mDevice->deleteStream(mPreviewStreamId); |
| 1718 | if (res != OK) { |
| 1719 | ALOGE("%s: Camera %d: Unable to delete old output stream " |
| 1720 | "for preview: %s (%d)", __FUNCTION__, mCameraId, |
| 1721 | strerror(-res), res); |
| 1722 | return res; |
| 1723 | } |
| 1724 | mPreviewStreamId = NO_STREAM; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | if (mPreviewStreamId == NO_STREAM) { |
| 1729 | res = mDevice->createStream(mPreviewWindow, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1730 | params.previewWidth, params.previewHeight, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1731 | CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, 0, |
| 1732 | &mPreviewStreamId); |
| 1733 | if (res != OK) { |
| 1734 | ALOGE("%s: Camera %d: Unable to create preview stream: %s (%d)", |
| 1735 | __FUNCTION__, mCameraId, strerror(-res), res); |
| 1736 | return res; |
| 1737 | } |
| 1738 | } |
| 1739 | |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1740 | res = mDevice->setStreamTransform(mPreviewStreamId, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1741 | params.previewTransform); |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1742 | if (res != OK) { |
| 1743 | ALOGE("%s: Camera %d: Unable to set preview stream transform: " |
| 1744 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1745 | return res; |
| 1746 | } |
| 1747 | |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1748 | return OK; |
| 1749 | } |
| 1750 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1751 | status_t Camera2Client::updatePreviewRequest(const Parameters ¶ms) { |
Eino-Ville Talvala | a189097 | 2012-05-31 11:18:52 -0700 | [diff] [blame] | 1752 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1753 | status_t res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1754 | if (mPreviewRequest.entryCount() == 0) { |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1755 | res = mDevice->createDefaultRequest(CAMERA2_TEMPLATE_PREVIEW, |
| 1756 | &mPreviewRequest); |
| 1757 | if (res != OK) { |
| 1758 | ALOGE("%s: Camera %d: Unable to create default preview request: " |
| 1759 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1760 | return res; |
| 1761 | } |
| 1762 | } |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1763 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1764 | res = updateRequestCommon(&mPreviewRequest, params); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1765 | if (res != OK) { |
| 1766 | ALOGE("%s: Camera %d: Unable to update common entries of preview " |
| 1767 | "request: %s (%d)", __FUNCTION__, mCameraId, |
| 1768 | strerror(-res), res); |
| 1769 | return res; |
| 1770 | } |
| 1771 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1772 | return OK; |
| 1773 | } |
| 1774 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1775 | status_t Camera2Client::updateCaptureRequest(const Parameters ¶ms) { |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1776 | ATRACE_CALL(); |
| 1777 | status_t res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1778 | if (mCaptureRequest.entryCount() == 0) { |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1779 | res = mDevice->createDefaultRequest(CAMERA2_TEMPLATE_STILL_CAPTURE, |
| 1780 | &mCaptureRequest); |
| 1781 | if (res != OK) { |
| 1782 | ALOGE("%s: Camera %d: Unable to create default still image request:" |
| 1783 | " %s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1784 | return res; |
| 1785 | } |
| 1786 | } |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1787 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1788 | res = updateRequestCommon(&mCaptureRequest, params); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1789 | if (res != OK) { |
| 1790 | ALOGE("%s: Camera %d: Unable to update common entries of capture " |
| 1791 | "request: %s (%d)", __FUNCTION__, mCameraId, |
| 1792 | strerror(-res), res); |
| 1793 | return res; |
| 1794 | } |
| 1795 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1796 | res = mCaptureRequest.update(ANDROID_JPEG_THUMBNAIL_SIZE, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1797 | params.jpegThumbSize, 2); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1798 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1799 | res = mCaptureRequest.update(ANDROID_JPEG_THUMBNAIL_QUALITY, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1800 | ¶ms.jpegThumbQuality, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1801 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1802 | res = mCaptureRequest.update(ANDROID_JPEG_QUALITY, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1803 | ¶ms.jpegQuality, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1804 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1805 | res = mCaptureRequest.update( |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1806 | ANDROID_JPEG_ORIENTATION, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1807 | ¶ms.jpegRotation, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1808 | if (res != OK) return res; |
| 1809 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1810 | if (params.gpsEnabled) { |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1811 | res = mCaptureRequest.update( |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1812 | ANDROID_JPEG_GPS_COORDINATES, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1813 | params.gpsCoordinates, 3); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1814 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1815 | res = mCaptureRequest.update( |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1816 | ANDROID_JPEG_GPS_TIMESTAMP, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1817 | ¶ms.gpsTimestamp, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1818 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1819 | res = mCaptureRequest.update( |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1820 | ANDROID_JPEG_GPS_PROCESSING_METHOD, |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1821 | params.gpsProcessingMethod); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1822 | if (res != OK) return res; |
| 1823 | } else { |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1824 | res = mCaptureRequest.erase(ANDROID_JPEG_GPS_COORDINATES); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1825 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1826 | res = mCaptureRequest.erase(ANDROID_JPEG_GPS_TIMESTAMP); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1827 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1828 | res = mCaptureRequest.erase(ANDROID_JPEG_GPS_PROCESSING_METHOD); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1829 | if (res != OK) return res; |
| 1830 | } |
| 1831 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1832 | return OK; |
| 1833 | } |
| 1834 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1835 | status_t Camera2Client::updateRecordingRequest(const Parameters ¶ms) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1836 | ATRACE_CALL(); |
| 1837 | status_t res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1838 | if (mRecordingRequest.entryCount() == 0) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1839 | res = mDevice->createDefaultRequest(CAMERA2_TEMPLATE_VIDEO_RECORD, |
| 1840 | &mRecordingRequest); |
| 1841 | if (res != OK) { |
| 1842 | ALOGE("%s: Camera %d: Unable to create default recording request:" |
| 1843 | " %s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1844 | return res; |
| 1845 | } |
| 1846 | } |
| 1847 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1848 | res = updateRequestCommon(&mRecordingRequest, params); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1849 | if (res != OK) { |
| 1850 | ALOGE("%s: Camera %d: Unable to update common entries of recording " |
| 1851 | "request: %s (%d)", __FUNCTION__, mCameraId, |
| 1852 | strerror(-res), res); |
| 1853 | return res; |
| 1854 | } |
| 1855 | |
| 1856 | return OK; |
| 1857 | } |
| 1858 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1859 | status_t Camera2Client::updateRecordingStream(const Parameters ¶ms) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1860 | status_t res; |
| 1861 | |
| 1862 | if (mRecordingConsumer == 0) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1863 | // Create CPU buffer queue endpoint. We need one more buffer here so that we can |
| 1864 | // always acquire and free a buffer when the heap is full; otherwise the consumer |
| 1865 | // will have buffers in flight we'll never clear out. |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 1866 | mRecordingConsumer = new BufferItemConsumer( |
| 1867 | GRALLOC_USAGE_HW_VIDEO_ENCODER, |
| 1868 | mRecordingHeapCount + 1, |
| 1869 | true); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1870 | mRecordingConsumer->setFrameAvailableListener(new RecordingWaiter(this)); |
| 1871 | mRecordingConsumer->setName(String8("Camera2Client::RecordingConsumer")); |
| 1872 | mRecordingWindow = new SurfaceTextureClient( |
| 1873 | mRecordingConsumer->getProducerInterface()); |
| 1874 | // Allocate memory later, since we don't know buffer size until receipt |
| 1875 | } |
| 1876 | |
| 1877 | if (mRecordingStreamId != NO_STREAM) { |
| 1878 | // Check if stream parameters have to change |
| 1879 | uint32_t currentWidth, currentHeight; |
| 1880 | res = mDevice->getStreamInfo(mRecordingStreamId, |
| 1881 | ¤tWidth, ¤tHeight, 0); |
| 1882 | if (res != OK) { |
| 1883 | ALOGE("%s: Camera %d: Error querying recording output stream info: " |
| 1884 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1885 | return res; |
| 1886 | } |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1887 | if (currentWidth != (uint32_t)params.videoWidth || |
| 1888 | currentHeight != (uint32_t)params.videoHeight) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1889 | // TODO: Should wait to be sure previous recording has finished |
| 1890 | res = mDevice->deleteStream(mRecordingStreamId); |
| 1891 | if (res != OK) { |
| 1892 | ALOGE("%s: Camera %d: Unable to delete old output stream " |
| 1893 | "for recording: %s (%d)", __FUNCTION__, mCameraId, |
| 1894 | strerror(-res), res); |
| 1895 | return res; |
| 1896 | } |
| 1897 | mRecordingStreamId = NO_STREAM; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | if (mRecordingStreamId == NO_STREAM) { |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1902 | mRecordingFrameCount = 0; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1903 | res = mDevice->createStream(mRecordingWindow, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1904 | params.videoWidth, params.videoHeight, |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 1905 | CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, 0, &mRecordingStreamId); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1906 | if (res != OK) { |
| 1907 | ALOGE("%s: Camera %d: Can't create output stream for recording: " |
| 1908 | "%s (%d)", __FUNCTION__, mCameraId, strerror(-res), res); |
| 1909 | return res; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | return OK; |
| 1914 | } |
| 1915 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1916 | status_t Camera2Client::updateRequestCommon(CameraMetadata *request, |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1917 | const Parameters ¶ms) const { |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1918 | ATRACE_CALL(); |
| 1919 | status_t res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1920 | res = request->update(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 1921 | params.previewFpsRange, 2); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1922 | if (res != OK) return res; |
| 1923 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1924 | uint8_t wbMode = params.autoWhiteBalanceLock ? |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1925 | (uint8_t)ANDROID_CONTROL_AWB_LOCKED : params.wbMode; |
| 1926 | res = request->update(ANDROID_CONTROL_AWB_MODE, |
| 1927 | &wbMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1928 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1929 | res = request->update(ANDROID_CONTROL_EFFECT_MODE, |
| 1930 | ¶ms.effectMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1931 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1932 | res = request->update(ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1933 | ¶ms.antibandingMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1934 | if (res != OK) return res; |
| 1935 | |
| 1936 | uint8_t controlMode = |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1937 | (params.sceneMode == ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED) ? |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1938 | ANDROID_CONTROL_AUTO : ANDROID_CONTROL_USE_SCENE_MODE; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1939 | res = request->update(ANDROID_CONTROL_MODE, |
| 1940 | &controlMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1941 | if (res != OK) return res; |
| 1942 | if (controlMode == ANDROID_CONTROL_USE_SCENE_MODE) { |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1943 | res = request->update(ANDROID_CONTROL_SCENE_MODE, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1944 | ¶ms.sceneMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1945 | if (res != OK) return res; |
| 1946 | } |
| 1947 | |
| 1948 | uint8_t flashMode = ANDROID_FLASH_OFF; |
| 1949 | uint8_t aeMode; |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1950 | switch (params.flashMode) { |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1951 | case Parameters::FLASH_MODE_OFF: |
| 1952 | aeMode = ANDROID_CONTROL_AE_ON; break; |
| 1953 | case Parameters::FLASH_MODE_AUTO: |
| 1954 | aeMode = ANDROID_CONTROL_AE_ON_AUTO_FLASH; break; |
| 1955 | case Parameters::FLASH_MODE_ON: |
| 1956 | aeMode = ANDROID_CONTROL_AE_ON_ALWAYS_FLASH; break; |
| 1957 | case Parameters::FLASH_MODE_TORCH: |
| 1958 | aeMode = ANDROID_CONTROL_AE_ON; |
| 1959 | flashMode = ANDROID_FLASH_TORCH; |
| 1960 | break; |
| 1961 | case Parameters::FLASH_MODE_RED_EYE: |
| 1962 | aeMode = ANDROID_CONTROL_AE_ON_AUTO_FLASH_REDEYE; break; |
| 1963 | default: |
| 1964 | ALOGE("%s: Camera %d: Unknown flash mode %d", __FUNCTION__, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1965 | mCameraId, params.flashMode); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1966 | return BAD_VALUE; |
| 1967 | } |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1968 | if (params.autoExposureLock) aeMode = ANDROID_CONTROL_AE_LOCKED; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1969 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1970 | res = request->update(ANDROID_FLASH_MODE, |
| 1971 | &flashMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1972 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1973 | res = request->update(ANDROID_CONTROL_AE_MODE, |
| 1974 | &aeMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1975 | if (res != OK) return res; |
| 1976 | |
| 1977 | float focusDistance = 0; // infinity focus in diopters |
| 1978 | uint8_t focusMode; |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1979 | switch (params.focusMode) { |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1980 | case Parameters::FOCUS_MODE_AUTO: |
| 1981 | case Parameters::FOCUS_MODE_MACRO: |
| 1982 | case Parameters::FOCUS_MODE_CONTINUOUS_VIDEO: |
| 1983 | case Parameters::FOCUS_MODE_CONTINUOUS_PICTURE: |
| 1984 | case Parameters::FOCUS_MODE_EDOF: |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1985 | focusMode = params.focusMode; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1986 | break; |
| 1987 | case Parameters::FOCUS_MODE_INFINITY: |
| 1988 | case Parameters::FOCUS_MODE_FIXED: |
| 1989 | focusMode = ANDROID_CONTROL_AF_OFF; |
| 1990 | break; |
| 1991 | default: |
| 1992 | ALOGE("%s: Camera %d: Unknown focus mode %d", __FUNCTION__, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 1993 | mCameraId, params.focusMode); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1994 | return BAD_VALUE; |
| 1995 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1996 | res = request->update(ANDROID_LENS_FOCUS_DISTANCE, |
| 1997 | &focusDistance, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 1998 | if (res != OK) return res; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1999 | res = request->update(ANDROID_CONTROL_AF_MODE, |
| 2000 | &focusMode, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2001 | if (res != OK) return res; |
| 2002 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2003 | size_t focusingAreasSize = params.focusingAreas.size() * 5; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2004 | int32_t *focusingAreas = new int32_t[focusingAreasSize]; |
| 2005 | for (size_t i = 0; i < focusingAreasSize; i += 5) { |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2006 | if (params.focusingAreas[i].weight != 0) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2007 | focusingAreas[i + 0] = |
| 2008 | params.normalizedXToArray(params.focusingAreas[i].left); |
| 2009 | focusingAreas[i + 1] = |
| 2010 | params.normalizedYToArray(params.focusingAreas[i].top); |
| 2011 | focusingAreas[i + 2] = |
| 2012 | params.normalizedXToArray(params.focusingAreas[i].right); |
| 2013 | focusingAreas[i + 3] = |
| 2014 | params.normalizedYToArray(params.focusingAreas[i].bottom); |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2015 | } else { |
| 2016 | focusingAreas[i + 0] = 0; |
| 2017 | focusingAreas[i + 1] = 0; |
| 2018 | focusingAreas[i + 2] = 0; |
| 2019 | focusingAreas[i + 3] = 0; |
| 2020 | } |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2021 | focusingAreas[i + 4] = params.focusingAreas[i].weight; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2022 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2023 | res = request->update(ANDROID_CONTROL_AF_REGIONS, |
| 2024 | focusingAreas,focusingAreasSize); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2025 | if (res != OK) return res; |
| 2026 | delete[] focusingAreas; |
| 2027 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2028 | res = request->update(ANDROID_CONTROL_AE_EXP_COMPENSATION, |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2029 | ¶ms.exposureCompensation, 1); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2030 | if (res != OK) return res; |
| 2031 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2032 | size_t meteringAreasSize = params.meteringAreas.size() * 5; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2033 | int32_t *meteringAreas = new int32_t[meteringAreasSize]; |
| 2034 | for (size_t i = 0; i < meteringAreasSize; i += 5) { |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2035 | if (params.meteringAreas[i].weight != 0) { |
| 2036 | meteringAreas[i + 0] = |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2037 | params.normalizedXToArray(params.meteringAreas[i].left); |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2038 | meteringAreas[i + 1] = |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2039 | params.normalizedYToArray(params.meteringAreas[i].top); |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2040 | meteringAreas[i + 2] = |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2041 | params.normalizedXToArray(params.meteringAreas[i].right); |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2042 | meteringAreas[i + 3] = |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2043 | params.normalizedYToArray(params.meteringAreas[i].bottom); |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2044 | } else { |
| 2045 | meteringAreas[i + 0] = 0; |
| 2046 | meteringAreas[i + 1] = 0; |
| 2047 | meteringAreas[i + 2] = 0; |
| 2048 | meteringAreas[i + 3] = 0; |
| 2049 | } |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2050 | meteringAreas[i + 4] = params.meteringAreas[i].weight; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2051 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2052 | res = request->update(ANDROID_CONTROL_AE_REGIONS, |
| 2053 | meteringAreas, meteringAreasSize); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2054 | if (res != OK) return res; |
| 2055 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2056 | res = request->update(ANDROID_CONTROL_AWB_REGIONS, |
| 2057 | meteringAreas, meteringAreasSize); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2058 | if (res != OK) return res; |
| 2059 | delete[] meteringAreas; |
| 2060 | |
| 2061 | // Need to convert zoom index into a crop rectangle. The rectangle is |
| 2062 | // chosen to maximize its area on the sensor |
| 2063 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2064 | camera_metadata_ro_entry_t maxDigitalZoom = |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2065 | mParameters.staticInfo(ANDROID_SCALER_AVAILABLE_MAX_ZOOM); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2066 | float zoomIncrement = (maxDigitalZoom.data.f[0] - 1) / |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2067 | (params.NUM_ZOOM_STEPS-1); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2068 | float zoomRatio = 1 + zoomIncrement * params.zoom; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2069 | |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2070 | float zoomLeft, zoomTop, zoomWidth, zoomHeight; |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2071 | if (params.previewWidth >= params.previewHeight) { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2072 | zoomWidth = params.fastInfo.arrayWidth / zoomRatio; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2073 | zoomHeight = zoomWidth * |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2074 | params.previewHeight / params.previewWidth; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2075 | } else { |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2076 | zoomHeight = params.fastInfo.arrayHeight / zoomRatio; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2077 | zoomWidth = zoomHeight * |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2078 | params.previewWidth / params.previewHeight; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2079 | } |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2080 | zoomLeft = (params.fastInfo.arrayWidth - zoomWidth) / 2; |
| 2081 | zoomTop = (params.fastInfo.arrayHeight - zoomHeight) / 2; |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2082 | |
| 2083 | int32_t cropRegion[3] = { zoomLeft, zoomTop, zoomWidth }; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2084 | res = request->update(ANDROID_SCALER_CROP_REGION, |
| 2085 | cropRegion, 3); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2086 | if (res != OK) return res; |
| 2087 | |
| 2088 | // TODO: Decide how to map recordingHint, or whether just to ignore it |
| 2089 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 2090 | uint8_t vstabMode = params.videoStabilization ? |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2091 | ANDROID_CONTROL_VIDEO_STABILIZATION_ON : |
| 2092 | ANDROID_CONTROL_VIDEO_STABILIZATION_OFF; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2093 | res = request->update(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2094 | &vstabMode, 1); |
| 2095 | if (res != OK) return res; |
| 2096 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 2097 | uint8_t faceDetectMode = params.enableFaceDetect ? |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 2098 | params.fastInfo.bestFaceDetectMode : |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 2099 | (uint8_t)ANDROID_STATS_FACE_DETECTION_OFF; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 2100 | res = request->update(ANDROID_STATS_FACE_DETECT_MODE, |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 2101 | &faceDetectMode, 1); |
| 2102 | if (res != OK) return res; |
| 2103 | |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 2104 | return OK; |
| 2105 | } |
| 2106 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 2107 | size_t Camera2Client::calculateBufferSize(int width, int height, |
| 2108 | int format, int stride) { |
| 2109 | switch (format) { |
| 2110 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: // NV16 |
| 2111 | return width * height * 2; |
| 2112 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: // NV21 |
| 2113 | return width * height * 3 / 2; |
| 2114 | case HAL_PIXEL_FORMAT_YCbCr_422_I: // YUY2 |
| 2115 | return width * height * 2; |
| 2116 | case HAL_PIXEL_FORMAT_YV12: { // YV12 |
| 2117 | size_t ySize = stride * height; |
Eino-Ville Talvala | f17b6cf | 2012-08-25 17:12:18 -0700 | [diff] [blame] | 2118 | size_t uvStride = (stride / 2 + 0xF) & ~0xF; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 2119 | size_t uvSize = uvStride * height / 2; |
| 2120 | return ySize + uvSize * 2; |
| 2121 | } |
| 2122 | case HAL_PIXEL_FORMAT_RGB_565: |
| 2123 | return width * height * 2; |
| 2124 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 2125 | return width * height * 4; |
| 2126 | case HAL_PIXEL_FORMAT_RAW_SENSOR: |
| 2127 | return width * height * 2; |
| 2128 | default: |
| 2129 | ALOGE("%s: Unknown preview format: %x", |
| 2130 | __FUNCTION__, format); |
| 2131 | return 0; |
| 2132 | } |
| 2133 | } |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 2134 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 2135 | } // namespace android |