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