Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright (C) 2008, The Android Open Source Project |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "Camera" |
| 20 | #include <utils/Log.h> |
| 21 | #include <utils/threads.h> |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 22 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <binder/IServiceManager.h> |
| 24 | #include <binder/IMemory.h> |
| 25 | |
| 26 | #include <camera/Camera.h> |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 27 | #include <camera/ICameraRecordingProxyListener.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 28 | #include <camera/ICameraService.h> |
| 29 | |
| 30 | #include <surfaceflinger/Surface.h> |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | // client singleton for camera service binder interface |
| 35 | Mutex Camera::mLock; |
| 36 | sp<ICameraService> Camera::mCameraService; |
| 37 | sp<Camera::DeathNotifier> Camera::mDeathNotifier; |
| 38 | |
| 39 | // establish binder interface to camera service |
| 40 | const sp<ICameraService>& Camera::getCameraService() |
| 41 | { |
| 42 | Mutex::Autolock _l(mLock); |
| 43 | if (mCameraService.get() == 0) { |
| 44 | sp<IServiceManager> sm = defaultServiceManager(); |
| 45 | sp<IBinder> binder; |
| 46 | do { |
| 47 | binder = sm->getService(String16("media.camera")); |
| 48 | if (binder != 0) |
| 49 | break; |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 50 | ALOGW("CameraService not published, waiting..."); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 51 | usleep(500000); // 0.5 s |
| 52 | } while(true); |
| 53 | if (mDeathNotifier == NULL) { |
| 54 | mDeathNotifier = new DeathNotifier(); |
| 55 | } |
| 56 | binder->linkToDeath(mDeathNotifier); |
| 57 | mCameraService = interface_cast<ICameraService>(binder); |
| 58 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 59 | ALOGE_IF(mCameraService==0, "no CameraService!?"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 60 | return mCameraService; |
| 61 | } |
| 62 | |
| 63 | // --------------------------------------------------------------------------- |
| 64 | |
| 65 | Camera::Camera() |
| 66 | { |
| 67 | init(); |
| 68 | } |
| 69 | |
| 70 | // construct a camera client from an existing camera remote |
| 71 | sp<Camera> Camera::create(const sp<ICamera>& camera) |
| 72 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 73 | ALOGV("create"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 74 | if (camera == 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 75 | ALOGE("camera remote is a NULL pointer"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | sp<Camera> c = new Camera(); |
| 80 | if (camera->connect(c) == NO_ERROR) { |
| 81 | c->mStatus = NO_ERROR; |
| 82 | c->mCamera = camera; |
| 83 | camera->asBinder()->linkToDeath(c); |
Wu-cheng Li | 627baac | 2011-01-04 20:00:55 +0800 | [diff] [blame] | 84 | return c; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 85 | } |
Wu-cheng Li | 627baac | 2011-01-04 20:00:55 +0800 | [diff] [blame] | 86 | return 0; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void Camera::init() |
| 90 | { |
| 91 | mStatus = UNKNOWN_ERROR; |
| 92 | } |
| 93 | |
| 94 | Camera::~Camera() |
| 95 | { |
Chih-Chung Chang | d06618e | 2010-05-13 15:14:24 +0800 | [diff] [blame] | 96 | // We don't need to call disconnect() here because if the CameraService |
| 97 | // thinks we are the owner of the hardware, it will hold a (strong) |
| 98 | // reference to us, and we can't possibly be here. We also don't want to |
| 99 | // call disconnect() here if we are in the same process as mediaserver, |
| 100 | // because we may be invoked by CameraService::Client::connect() and will |
| 101 | // deadlock if we call any method of ICamera here. |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 104 | int32_t Camera::getNumberOfCameras() |
| 105 | { |
| 106 | const sp<ICameraService>& cs = getCameraService(); |
| 107 | if (cs == 0) return 0; |
| 108 | return cs->getNumberOfCameras(); |
| 109 | } |
| 110 | |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 111 | status_t Camera::getCameraInfo(int cameraId, |
| 112 | struct CameraInfo* cameraInfo) { |
| 113 | const sp<ICameraService>& cs = getCameraService(); |
| 114 | if (cs == 0) return UNKNOWN_ERROR; |
| 115 | return cs->getCameraInfo(cameraId, cameraInfo); |
| 116 | } |
| 117 | |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 118 | sp<Camera> Camera::connect(int cameraId) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 119 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 120 | ALOGV("connect"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 121 | sp<Camera> c = new Camera(); |
| 122 | const sp<ICameraService>& cs = getCameraService(); |
| 123 | if (cs != 0) { |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 124 | c->mCamera = cs->connect(c, cameraId); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 125 | } |
| 126 | if (c->mCamera != 0) { |
| 127 | c->mCamera->asBinder()->linkToDeath(c); |
| 128 | c->mStatus = NO_ERROR; |
| 129 | } else { |
| 130 | c.clear(); |
| 131 | } |
| 132 | return c; |
| 133 | } |
| 134 | |
| 135 | void Camera::disconnect() |
| 136 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 137 | ALOGV("disconnect"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 138 | if (mCamera != 0) { |
| 139 | mCamera->disconnect(); |
Chih-Chung Chang | f8ed70a | 2010-03-24 16:38:02 -0700 | [diff] [blame] | 140 | mCamera->asBinder()->unlinkToDeath(this); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 141 | mCamera = 0; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | status_t Camera::reconnect() |
| 146 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 147 | ALOGV("reconnect"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 148 | sp <ICamera> c = mCamera; |
| 149 | if (c == 0) return NO_INIT; |
| 150 | return c->connect(this); |
| 151 | } |
| 152 | |
| 153 | sp<ICamera> Camera::remote() |
| 154 | { |
| 155 | return mCamera; |
| 156 | } |
| 157 | |
| 158 | status_t Camera::lock() |
| 159 | { |
| 160 | sp <ICamera> c = mCamera; |
| 161 | if (c == 0) return NO_INIT; |
| 162 | return c->lock(); |
| 163 | } |
| 164 | |
| 165 | status_t Camera::unlock() |
| 166 | { |
| 167 | sp <ICamera> c = mCamera; |
| 168 | if (c == 0) return NO_INIT; |
| 169 | return c->unlock(); |
| 170 | } |
| 171 | |
Jamie Gennis | 4b79168 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 172 | // pass the buffered Surface to the camera service |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 173 | status_t Camera::setPreviewDisplay(const sp<Surface>& surface) |
| 174 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 175 | ALOGV("setPreviewDisplay(%p)", surface.get()); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 176 | sp <ICamera> c = mCamera; |
| 177 | if (c == 0) return NO_INIT; |
| 178 | if (surface != 0) { |
Jamie Gennis | 4b79168 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 179 | return c->setPreviewDisplay(surface); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 180 | } else { |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 181 | ALOGD("app passed NULL surface"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 182 | return c->setPreviewDisplay(0); |
| 183 | } |
| 184 | } |
| 185 | |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 186 | // pass the buffered ISurfaceTexture to the camera service |
| 187 | status_t Camera::setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture) |
| 188 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 189 | ALOGV("setPreviewTexture(%p)", surfaceTexture.get()); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 190 | sp <ICamera> c = mCamera; |
| 191 | if (c == 0) return NO_INIT; |
| 192 | if (surfaceTexture != 0) { |
| 193 | return c->setPreviewTexture(surfaceTexture); |
| 194 | } else { |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 195 | ALOGD("app passed NULL surface"); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 196 | return c->setPreviewTexture(0); |
| 197 | } |
| 198 | } |
| 199 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 200 | // start preview mode |
| 201 | status_t Camera::startPreview() |
| 202 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 203 | ALOGV("startPreview"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 204 | sp <ICamera> c = mCamera; |
| 205 | if (c == 0) return NO_INIT; |
| 206 | return c->startPreview(); |
| 207 | } |
| 208 | |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 209 | status_t Camera::storeMetaDataInBuffers(bool enabled) |
| 210 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 211 | ALOGV("storeMetaDataInBuffers: %s", |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 212 | enabled? "true": "false"); |
| 213 | sp <ICamera> c = mCamera; |
| 214 | if (c == 0) return NO_INIT; |
| 215 | return c->storeMetaDataInBuffers(enabled); |
| 216 | } |
| 217 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 218 | // start recording mode, must call setPreviewDisplay first |
| 219 | status_t Camera::startRecording() |
| 220 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 221 | ALOGV("startRecording"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 222 | sp <ICamera> c = mCamera; |
| 223 | if (c == 0) return NO_INIT; |
| 224 | return c->startRecording(); |
| 225 | } |
| 226 | |
| 227 | // stop preview mode |
| 228 | void Camera::stopPreview() |
| 229 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 230 | ALOGV("stopPreview"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 231 | sp <ICamera> c = mCamera; |
| 232 | if (c == 0) return; |
| 233 | c->stopPreview(); |
| 234 | } |
| 235 | |
| 236 | // stop recording mode |
| 237 | void Camera::stopRecording() |
| 238 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 239 | ALOGV("stopRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 240 | { |
| 241 | Mutex::Autolock _l(mLock); |
| 242 | mRecordingProxyListener.clear(); |
| 243 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 244 | sp <ICamera> c = mCamera; |
| 245 | if (c == 0) return; |
| 246 | c->stopRecording(); |
| 247 | } |
| 248 | |
| 249 | // release a recording frame |
| 250 | void Camera::releaseRecordingFrame(const sp<IMemory>& mem) |
| 251 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 252 | ALOGV("releaseRecordingFrame"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 253 | sp <ICamera> c = mCamera; |
| 254 | if (c == 0) return; |
| 255 | c->releaseRecordingFrame(mem); |
| 256 | } |
| 257 | |
| 258 | // get preview state |
| 259 | bool Camera::previewEnabled() |
| 260 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 261 | ALOGV("previewEnabled"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 262 | sp <ICamera> c = mCamera; |
| 263 | if (c == 0) return false; |
| 264 | return c->previewEnabled(); |
| 265 | } |
| 266 | |
| 267 | // get recording state |
| 268 | bool Camera::recordingEnabled() |
| 269 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 270 | ALOGV("recordingEnabled"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 271 | sp <ICamera> c = mCamera; |
| 272 | if (c == 0) return false; |
| 273 | return c->recordingEnabled(); |
| 274 | } |
| 275 | |
| 276 | status_t Camera::autoFocus() |
| 277 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 278 | ALOGV("autoFocus"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 279 | sp <ICamera> c = mCamera; |
| 280 | if (c == 0) return NO_INIT; |
| 281 | return c->autoFocus(); |
| 282 | } |
| 283 | |
| 284 | status_t Camera::cancelAutoFocus() |
| 285 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 286 | ALOGV("cancelAutoFocus"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 287 | sp <ICamera> c = mCamera; |
| 288 | if (c == 0) return NO_INIT; |
| 289 | return c->cancelAutoFocus(); |
| 290 | } |
| 291 | |
| 292 | // take a picture |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 293 | status_t Camera::takePicture(int msgType) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 294 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 295 | ALOGV("takePicture: 0x%x", msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 296 | sp <ICamera> c = mCamera; |
| 297 | if (c == 0) return NO_INIT; |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 298 | return c->takePicture(msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | // set preview/capture parameters - key/value pairs |
| 302 | status_t Camera::setParameters(const String8& params) |
| 303 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 304 | ALOGV("setParameters"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 305 | sp <ICamera> c = mCamera; |
| 306 | if (c == 0) return NO_INIT; |
| 307 | return c->setParameters(params); |
| 308 | } |
| 309 | |
| 310 | // get preview/capture parameters - key/value pairs |
| 311 | String8 Camera::getParameters() const |
| 312 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 313 | ALOGV("getParameters"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 314 | String8 params; |
| 315 | sp <ICamera> c = mCamera; |
| 316 | if (c != 0) params = mCamera->getParameters(); |
| 317 | return params; |
| 318 | } |
| 319 | |
| 320 | // send command to camera driver |
| 321 | status_t Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) |
| 322 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 323 | ALOGV("sendCommand"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 324 | sp <ICamera> c = mCamera; |
| 325 | if (c == 0) return NO_INIT; |
| 326 | return c->sendCommand(cmd, arg1, arg2); |
| 327 | } |
| 328 | |
| 329 | void Camera::setListener(const sp<CameraListener>& listener) |
| 330 | { |
| 331 | Mutex::Autolock _l(mLock); |
| 332 | mListener = listener; |
| 333 | } |
| 334 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 335 | void Camera::setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener) |
| 336 | { |
| 337 | Mutex::Autolock _l(mLock); |
| 338 | mRecordingProxyListener = listener; |
| 339 | } |
| 340 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 341 | void Camera::setPreviewCallbackFlags(int flag) |
| 342 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 343 | ALOGV("setPreviewCallbackFlags"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 344 | sp <ICamera> c = mCamera; |
| 345 | if (c == 0) return; |
| 346 | mCamera->setPreviewCallbackFlag(flag); |
| 347 | } |
| 348 | |
| 349 | // callback from camera service |
| 350 | void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) |
| 351 | { |
| 352 | sp<CameraListener> listener; |
| 353 | { |
| 354 | Mutex::Autolock _l(mLock); |
| 355 | listener = mListener; |
| 356 | } |
| 357 | if (listener != NULL) { |
| 358 | listener->notify(msgType, ext1, ext2); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // callback from camera service when frame or image is ready |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 363 | void Camera::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, |
| 364 | camera_frame_metadata_t *metadata) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 365 | { |
| 366 | sp<CameraListener> listener; |
| 367 | { |
| 368 | Mutex::Autolock _l(mLock); |
| 369 | listener = mListener; |
| 370 | } |
| 371 | if (listener != NULL) { |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 372 | listener->postData(msgType, dataPtr, metadata); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
| 376 | // callback from camera service when timestamped frame is ready |
| 377 | void Camera::dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) |
| 378 | { |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 379 | // If recording proxy listener is registered, forward the frame and return. |
| 380 | // The other listener (mListener) is ignored because the receiver needs to |
| 381 | // call releaseRecordingFrame. |
| 382 | sp<ICameraRecordingProxyListener> proxylistener; |
| 383 | { |
| 384 | Mutex::Autolock _l(mLock); |
| 385 | proxylistener = mRecordingProxyListener; |
| 386 | } |
| 387 | if (proxylistener != NULL) { |
| 388 | proxylistener->dataCallbackTimestamp(timestamp, msgType, dataPtr); |
| 389 | return; |
| 390 | } |
| 391 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 392 | sp<CameraListener> listener; |
| 393 | { |
| 394 | Mutex::Autolock _l(mLock); |
| 395 | listener = mListener; |
| 396 | } |
| 397 | if (listener != NULL) { |
| 398 | listener->postDataTimestamp(timestamp, msgType, dataPtr); |
James Dong | c42478e | 2010-11-15 10:38:37 -0800 | [diff] [blame] | 399 | } else { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 400 | ALOGW("No listener was set. Drop a recording frame."); |
James Dong | c42478e | 2010-11-15 10:38:37 -0800 | [diff] [blame] | 401 | releaseRecordingFrame(dataPtr); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | void Camera::binderDied(const wp<IBinder>& who) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 406 | ALOGW("ICamera died"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 407 | notifyCallback(CAMERA_MSG_ERROR, CAMERA_ERROR_SERVER_DIED, 0); |
| 408 | } |
| 409 | |
| 410 | void Camera::DeathNotifier::binderDied(const wp<IBinder>& who) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 411 | ALOGV("binderDied"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 412 | Mutex::Autolock _l(Camera::mLock); |
| 413 | Camera::mCameraService.clear(); |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 414 | ALOGW("Camera server died!"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 417 | sp<ICameraRecordingProxy> Camera::getRecordingProxy() { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 418 | ALOGV("getProxy"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 419 | return new RecordingProxy(this); |
| 420 | } |
| 421 | |
| 422 | status_t Camera::RecordingProxy::startRecording(const sp<ICameraRecordingProxyListener>& listener) |
| 423 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 424 | ALOGV("RecordingProxy::startRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 425 | mCamera->setRecordingProxyListener(listener); |
| 426 | mCamera->reconnect(); |
| 427 | return mCamera->startRecording(); |
| 428 | } |
| 429 | |
| 430 | void Camera::RecordingProxy::stopRecording() |
| 431 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 432 | ALOGV("RecordingProxy::stopRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 433 | mCamera->stopRecording(); |
| 434 | } |
| 435 | |
| 436 | void Camera::RecordingProxy::releaseRecordingFrame(const sp<IMemory>& mem) |
| 437 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 438 | ALOGV("RecordingProxy::releaseRecordingFrame"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 439 | mCamera->releaseRecordingFrame(mem); |
| 440 | } |
| 441 | |
| 442 | Camera::RecordingProxy::RecordingProxy(const sp<Camera>& camera) |
| 443 | { |
| 444 | mCamera = camera; |
| 445 | } |
| 446 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 447 | }; // namespace android |