blob: fae1f2604131be97a894a86c1dc119ace7b03a49 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2**
3** Copyright (C) 2008, The Android Open Source Project
4** Copyright (C) 2008 HTC Inc.
5**
6** Licensed under the Apache License, Version 2.0 (the "License");
7** you may not use this file except in compliance with the License.
8** You may obtain a copy of the License at
9**
10** http://www.apache.org/licenses/LICENSE-2.0
11**
12** Unless required by applicable law or agreed to in writing, software
13** distributed under the License is distributed on an "AS IS" BASIS,
14** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15** See the License for the specific language governing permissions and
16** limitations under the License.
17*/
18
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019#define LOG_TAG "CameraService"
20#include <utils/Log.h>
21
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070022#include <binder/IServiceManager.h>
23#include <binder/IPCThreadState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024#include <utils/String16.h>
25#include <utils/Errors.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070026#include <binder/MemoryBase.h>
27#include <binder/MemoryHeapBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <ui/ICameraService.h>
29
Jason Sams78b877e2009-03-24 20:21:36 -070030#include <media/mediaplayer.h>
31#include <media/AudioSystem.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include "CameraService.h"
33
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +080034#include <cutils/atomic.h>
Eric Laurentcbcb00e2009-03-27 16:27:16 -070035
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036namespace android {
37
38extern "C" {
39#include <stdio.h>
40#include <sys/types.h>
41#include <sys/stat.h>
42#include <fcntl.h>
43#include <pthread.h>
Chih-Chung Changd98c5162009-06-22 16:03:41 +080044#include <signal.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045}
46
47// When you enable this, as well as DEBUG_REFS=1 and
48// DEBUG_REFS_ENABLED_BY_DEFAULT=0 in libutils/RefBase.cpp, this will track all
49// references to the CameraService::Client in order to catch the case where the
50// client is being destroyed while a callback from the CameraHardwareInterface
51// is outstanding. This is a serious bug because if we make another call into
52// CameraHardwreInterface that itself triggers a callback, we will deadlock.
53
54#define DEBUG_CLIENT_REFERENCES 0
55
56#define PICTURE_TIMEOUT seconds(5)
57
58#define DEBUG_DUMP_PREVIEW_FRAME_TO_FILE 0 /* n-th frame to write */
59#define DEBUG_DUMP_JPEG_SNAPSHOT_TO_FILE 0
60#define DEBUG_DUMP_YUV_SNAPSHOT_TO_FILE 0
Benny Wong4c8fb0a2009-08-12 12:01:27 -050061#define DEBUG_DUMP_POSTVIEW_SNAPSHOT_TO_FILE 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062
63#if DEBUG_DUMP_PREVIEW_FRAME_TO_FILE
64static int debug_frame_cnt;
65#endif
66
Chih-Chung Changd98c5162009-06-22 16:03:41 +080067static int getCallingPid() {
68 return IPCThreadState::self()->getCallingPid();
69}
70
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071// ----------------------------------------------------------------------------
72
73void CameraService::instantiate() {
74 defaultServiceManager()->addService(
75 String16("media.camera"), new CameraService());
76}
77
78// ----------------------------------------------------------------------------
79
80CameraService::CameraService() :
81 BnCameraService()
82{
83 LOGI("CameraService started: pid=%d", getpid());
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +080084 mUsers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085}
86
87CameraService::~CameraService()
88{
89 if (mClient != 0) {
90 LOGE("mClient was still connected in destructor!");
91 }
92}
93
94sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient)
95{
Chih-Chung Changd98c5162009-06-22 16:03:41 +080096 int callingPid = getCallingPid();
Joe Onorato51632e82010-01-07 21:48:32 -050097 LOGV("CameraService::connect E (pid %d, client %p)", callingPid,
Chih-Chung Changd98c5162009-06-22 16:03:41 +080098 cameraClient->asBinder().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +0800100 Mutex::Autolock lock(mServiceLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101 sp<Client> client;
102 if (mClient != 0) {
103 sp<Client> currentClient = mClient.promote();
104 if (currentClient != 0) {
105 sp<ICameraClient> currentCameraClient(currentClient->getCameraClient());
106 if (cameraClient->asBinder() == currentCameraClient->asBinder()) {
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800107 // This is the same client reconnecting...
Joe Onorato51632e82010-01-07 21:48:32 -0500108 LOGV("CameraService::connect X (pid %d, same client %p) is reconnecting...",
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800109 callingPid, cameraClient->asBinder().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 return currentClient;
111 } else {
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800112 // It's another client... reject it
Joe Onorato51632e82010-01-07 21:48:32 -0500113 LOGV("CameraService::connect X (pid %d, new client %p) rejected. "
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800114 "(old pid %d, old client %p)",
115 callingPid, cameraClient->asBinder().get(),
116 currentClient->mClientPid, currentCameraClient->asBinder().get());
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800117 if (kill(currentClient->mClientPid, 0) == -1 && errno == ESRCH) {
Joe Onorato51632e82010-01-07 21:48:32 -0500118 LOGV("The old client is dead!");
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800119 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120 return client;
121 }
122 } else {
123 // can't promote, the previous client has died...
Joe Onorato51632e82010-01-07 21:48:32 -0500124 LOGV("New client (pid %d) connecting, old reference was dangling...",
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800125 callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126 mClient.clear();
127 }
128 }
129
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +0800130 if (mUsers > 0) {
Joe Onorato51632e82010-01-07 21:48:32 -0500131 LOGV("Still have client, rejected");
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +0800132 return client;
133 }
134
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 // create a new Client object
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800136 client = new Client(this, cameraClient, callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137 mClient = client;
138#if DEBUG_CLIENT_REFERENCES
139 // Enable tracking for this object, and track increments and decrements of
140 // the refcount.
141 client->trackMe(true, true);
142#endif
Joe Onorato51632e82010-01-07 21:48:32 -0500143 LOGV("CameraService::connect X");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 return client;
145}
146
147void CameraService::removeClient(const sp<ICameraClient>& cameraClient)
148{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800149 int callingPid = getCallingPid();
150
151 // Declare this outside the lock to make absolutely sure the
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800152 // destructor won't be called with the lock held.
153 sp<Client> client;
154
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +0800155 Mutex::Autolock lock(mServiceLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800156
157 if (mClient == 0) {
158 // This happens when we have already disconnected.
Joe Onorato51632e82010-01-07 21:48:32 -0500159 LOGV("removeClient (pid %d): already disconnected", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800160 return;
161 }
162
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800163 // Promote mClient. It can fail if we are called from this path:
164 // Client::~Client() -> disconnect() -> removeClient().
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165 client = mClient.promote();
166 if (client == 0) {
Joe Onorato51632e82010-01-07 21:48:32 -0500167 LOGV("removeClient (pid %d): no more strong reference", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 mClient.clear();
169 return;
170 }
171
172 if (cameraClient->asBinder() != client->getCameraClient()->asBinder()) {
173 // ugh! that's not our client!!
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800174 LOGW("removeClient (pid %d): mClient doesn't match!", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175 } else {
176 // okay, good, forget about mClient
177 mClient.clear();
178 }
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800179
Joe Onorato51632e82010-01-07 21:48:32 -0500180 LOGV("removeClient (pid %d) done", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181}
182
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800183// The reason we need this count is a new CameraService::connect() request may
184// come in while the previous Client's destructor has not been run or is still
185// running. If the last strong reference of the previous Client is gone but
186// destructor has not been run, we should not allow the new Client to be created
187// because we need to wait for the previous Client to tear down the hardware
188// first.
189void CameraService::incUsers() {
190 android_atomic_inc(&mUsers);
191}
192
193void CameraService::decUsers() {
194 android_atomic_dec(&mUsers);
195}
196
Wu-cheng Lie6a550d2009-09-28 16:14:58 -0700197static sp<MediaPlayer> newMediaPlayer(const char *file)
Jason Sams78b877e2009-03-24 20:21:36 -0700198{
199 sp<MediaPlayer> mp = new MediaPlayer();
200 if (mp->setDataSource(file) == NO_ERROR) {
Eric Laurent9d91ad52009-07-17 12:17:14 -0700201 mp->setAudioStreamType(AudioSystem::ENFORCED_AUDIBLE);
Jason Sams78b877e2009-03-24 20:21:36 -0700202 mp->prepare();
203 } else {
204 mp.clear();
205 LOGE("Failed to load CameraService sounds.");
206 }
207 return mp;
208}
209
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210CameraService::Client::Client(const sp<CameraService>& cameraService,
211 const sp<ICameraClient>& cameraClient, pid_t clientPid)
212{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800213 int callingPid = getCallingPid();
Joe Onorato51632e82010-01-07 21:48:32 -0500214 LOGV("Client::Client E (pid %d)", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215 mCameraService = cameraService;
216 mCameraClient = cameraClient;
217 mClientPid = clientPid;
218 mHardware = openCameraHardware();
219 mUseOverlay = mHardware->useOverlay();
220
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500221 mHardware->setCallbacks(notifyCallback,
222 dataCallback,
223 dataCallbackTimestamp,
224 mCameraService.get());
225
226 // Enable zoom, error, and focus messages by default
227 mHardware->enableMsgType(CAMERA_MSG_ERROR |
228 CAMERA_MSG_ZOOM |
229 CAMERA_MSG_FOCUS);
230
Jason Sams78b877e2009-03-24 20:21:36 -0700231 mMediaPlayerClick = newMediaPlayer("/system/media/audio/ui/camera_click.ogg");
232 mMediaPlayerBeep = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg");
Benny Wong71f77152009-07-15 18:44:27 -0500233 mOverlayW = 0;
234 mOverlayH = 0;
Jason Sams78b877e2009-03-24 20:21:36 -0700235
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800236 // Callback is disabled by default
237 mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800238 cameraService->incUsers();
Joe Onorato51632e82010-01-07 21:48:32 -0500239 LOGV("Client::Client X (pid %d)", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800240}
241
242status_t CameraService::Client::checkPid()
243{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800244 int callingPid = getCallingPid();
245 if (mClientPid == callingPid) return NO_ERROR;
246 LOGW("Attempt to use locked camera (client %p) from different process "
247 " (old pid %d, new pid %d)",
248 getCameraClient()->asBinder().get(), mClientPid, callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800249 return -EBUSY;
250}
251
252status_t CameraService::Client::lock()
253{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800254 int callingPid = getCallingPid();
Joe Onorato51632e82010-01-07 21:48:32 -0500255 LOGV("lock from pid %d (mClientPid %d)", callingPid, mClientPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 Mutex::Autolock _l(mLock);
257 // lock camera to this client if the the camera is unlocked
258 if (mClientPid == 0) {
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800259 mClientPid = callingPid;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800260 return NO_ERROR;
261 }
262 // returns NO_ERROR if the client already owns the camera, -EBUSY otherwise
263 return checkPid();
264}
265
266status_t CameraService::Client::unlock()
267{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800268 int callingPid = getCallingPid();
Joe Onorato51632e82010-01-07 21:48:32 -0500269 LOGV("unlock from pid %d (mClientPid %d)", callingPid, mClientPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800270 Mutex::Autolock _l(mLock);
271 // allow anyone to use camera
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272 status_t result = checkPid();
James Dong0ae13e32009-04-20 19:35:28 -0700273 if (result == NO_ERROR) {
274 mClientPid = 0;
Joe Onorato51632e82010-01-07 21:48:32 -0500275 LOGV("clear mCameraClient (pid %d)", callingPid);
James Dong0ae13e32009-04-20 19:35:28 -0700276 // we need to remove the reference so that when app goes
277 // away, the reference count goes to 0.
278 mCameraClient.clear();
279 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800280 return result;
281}
282
283status_t CameraService::Client::connect(const sp<ICameraClient>& client)
284{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800285 int callingPid = getCallingPid();
286
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800287 // connect a new process to the camera
Joe Onorato51632e82010-01-07 21:48:32 -0500288 LOGV("Client::connect E (pid %d, client %p)", callingPid, client->asBinder().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800289
290 // I hate this hack, but things get really ugly when the media recorder
291 // service is handing back the camera to the app. The ICameraClient
292 // destructor will be called during the same IPC, making it look like
293 // the remote client is trying to disconnect. This hack temporarily
294 // sets the mClientPid to an invalid pid to prevent the hardware from
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800295 // being torn down.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800296 {
297
298 // hold a reference to the old client or we will deadlock if the client is
299 // in the same process and we hold the lock when we remove the reference
300 sp<ICameraClient> oldClient;
301 {
302 Mutex::Autolock _l(mLock);
Chih-Chung Chang34e5a152009-06-09 13:56:44 +0800303 if (mClientPid != 0 && checkPid() != NO_ERROR) {
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800304 LOGW("Tried to connect to locked camera (old pid %d, new pid %d)",
305 mClientPid, callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800306 return -EBUSY;
307 }
308 oldClient = mCameraClient;
309
310 // did the client actually change?
Dave Sparks393eb792009-10-15 10:02:22 -0700311 if ((mCameraClient != NULL) && (client->asBinder() == mCameraClient->asBinder())) {
Joe Onorato51632e82010-01-07 21:48:32 -0500312 LOGV("Connect to the same client");
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800313 return NO_ERROR;
314 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315
316 mCameraClient = client;
317 mClientPid = -1;
318 mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
Joe Onorato51632e82010-01-07 21:48:32 -0500319 LOGV("Connect to the new client (pid %d, client %p)",
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800320 callingPid, mCameraClient->asBinder().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800321 }
322
323 }
324 // the old client destructor is called when oldClient goes out of scope
325 // now we set the new PID to lock the interface again
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800326 mClientPid = callingPid;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327
328 return NO_ERROR;
329}
330
331#if HAVE_ANDROID_OS
332static void *unregister_surface(void *arg)
333{
334 ISurface *surface = (ISurface *)arg;
335 surface->unregisterBuffers();
336 IPCThreadState::self()->flushCommands();
337 return NULL;
338}
339#endif
340
341CameraService::Client::~Client()
342{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800343 int callingPid = getCallingPid();
344
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800345 // tear down client
Joe Onorato51632e82010-01-07 21:48:32 -0500346 LOGV("Client::~Client E (pid %d, client %p)",
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800347 callingPid, getCameraClient()->asBinder().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800348 if (mSurface != 0 && !mUseOverlay) {
349#if HAVE_ANDROID_OS
350 pthread_t thr;
351 // We unregister the buffers in a different thread because binder does
352 // not let us make sychronous transactions in a binder destructor (that
353 // is, upon our reaching a refcount of zero.)
354 pthread_create(&thr, NULL,
355 unregister_surface,
356 mSurface.get());
357 pthread_join(thr, NULL);
358#else
359 mSurface->unregisterBuffers();
360#endif
361 }
362
Jason Sams9e431ac2009-03-24 20:36:57 -0700363 if (mMediaPlayerBeep.get() != NULL) {
364 mMediaPlayerBeep->disconnect();
365 mMediaPlayerBeep.clear();
366 }
367 if (mMediaPlayerClick.get() != NULL) {
368 mMediaPlayerClick->disconnect();
369 mMediaPlayerClick.clear();
370 }
Jason Sams78b877e2009-03-24 20:21:36 -0700371
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372 // make sure we tear down the hardware
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800373 mClientPid = callingPid;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374 disconnect();
Joe Onorato51632e82010-01-07 21:48:32 -0500375 LOGV("Client::~Client X (pid %d)", mClientPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376}
377
378void CameraService::Client::disconnect()
379{
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800380 int callingPid = getCallingPid();
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800381
Joe Onorato51632e82010-01-07 21:48:32 -0500382 LOGV("Client::disconnect() E (pid %d client %p)",
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800383 callingPid, getCameraClient()->asBinder().get());
384
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800385 Mutex::Autolock lock(mLock);
386 if (mClientPid <= 0) {
Joe Onorato51632e82010-01-07 21:48:32 -0500387 LOGV("camera is unlocked (mClientPid = %d), don't tear down hardware", mClientPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800388 return;
389 }
390 if (checkPid() != NO_ERROR) {
Joe Onorato51632e82010-01-07 21:48:32 -0500391 LOGV("Different client - don't disconnect");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800392 return;
393 }
394
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800395 // Make sure disconnect() is done once and once only, whether it is called
396 // from the user directly, or called by the destructor.
397 if (mHardware == 0) return;
398
Joe Onorato51632e82010-01-07 21:48:32 -0500399 LOGV("hardware teardown");
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800400 // Before destroying mHardware, we must make sure it's in the
401 // idle state.
402 mHardware->stopPreview();
403 // Cancel all picture callbacks.
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500404 mHardware->disableMsgType(CAMERA_MSG_SHUTTER |
405 CAMERA_MSG_POSTVIEW_FRAME |
406 CAMERA_MSG_RAW_IMAGE |
407 CAMERA_MSG_COMPRESSED_IMAGE);
408 mHardware->cancelPicture();
409 // Turn off remaining messages.
410 mHardware->disableMsgType(CAMERA_MSG_ALL_MSGS);
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800411 // Release the hardware resources.
412 mHardware->release();
Benny Wong71f77152009-07-15 18:44:27 -0500413 // Release the held overlay resources.
414 if (mUseOverlay)
415 {
416 mOverlayRef = 0;
417 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418 mHardware.clear();
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800419
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +0800420 mCameraService->removeClient(mCameraClient);
Chih-Chung Changfa89f9f2009-06-24 13:44:37 +0800421 mCameraService->decUsers();
422
Joe Onorato51632e82010-01-07 21:48:32 -0500423 LOGV("Client::disconnect() X (pid %d)", callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424}
425
426// pass the buffered ISurface to the camera service
427status_t CameraService::Client::setPreviewDisplay(const sp<ISurface>& surface)
428{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800429 LOGV("setPreviewDisplay(%p) (pid %d)",
Wu-cheng Li988fb622009-06-23 23:37:36 +0800430 ((surface == NULL) ? NULL : surface.get()), getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431 Mutex::Autolock lock(mLock);
432 status_t result = checkPid();
433 if (result != NO_ERROR) return result;
Wu-cheng Li988fb622009-06-23 23:37:36 +0800434
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800435 Mutex::Autolock surfaceLock(mSurfaceLock);
Wu-cheng Li988fb622009-06-23 23:37:36 +0800436 result = NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800437 // asBinder() is safe on NULL (returns NULL)
438 if (surface->asBinder() != mSurface->asBinder()) {
Benny Wong71f77152009-07-15 18:44:27 -0500439 if (mSurface != 0) {
Dave Sparkse7e93f92010-01-04 08:55:04 -0800440 LOGV("clearing old preview surface %p", mSurface.get());
Benny Wong71f77152009-07-15 18:44:27 -0500441 if ( !mUseOverlay)
442 {
443 mSurface->unregisterBuffers();
444 }
445 else
446 {
447 // Force the destruction of any previous overlay
448 sp<Overlay> dummy;
449 mHardware->setOverlay( dummy );
450 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800451 }
452 mSurface = surface;
Benny Wong71f77152009-07-15 18:44:27 -0500453 mOverlayRef = 0;
Wu-cheng Li988fb622009-06-23 23:37:36 +0800454 // If preview has been already started, set overlay or register preview
455 // buffers now.
456 if (mHardware->previewEnabled()) {
457 if (mUseOverlay) {
458 result = setOverlay();
459 } else if (mSurface != 0) {
460 result = registerPreviewBuffers();
461 }
462 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463 }
Wu-cheng Li988fb622009-06-23 23:37:36 +0800464 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800465}
466
467// set the preview callback flag to affect how the received frames from
468// preview are handled.
469void CameraService::Client::setPreviewCallbackFlag(int callback_flag)
470{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800471 LOGV("setPreviewCallbackFlag (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472 Mutex::Autolock lock(mLock);
473 if (checkPid() != NO_ERROR) return;
474 mPreviewCallbackFlag = callback_flag;
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500475
476 if(mUseOverlay) {
477 if(mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ENABLE_MASK)
478 mHardware->enableMsgType(CAMERA_MSG_PREVIEW_FRAME);
479 else
480 mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
481 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482}
483
Wu-cheng Li988fb622009-06-23 23:37:36 +0800484// start preview mode
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800485status_t CameraService::Client::startCameraMode(camera_mode mode)
486{
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800487 int callingPid = getCallingPid();
488
Dave Sparkse7e93f92010-01-04 08:55:04 -0800489 LOGV("startCameraMode(%d) (pid %d)", mode, callingPid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490
491 /* we cannot call into mHardware with mLock held because
492 * mHardware has callbacks onto us which acquire this lock
493 */
494
495 Mutex::Autolock lock(mLock);
496 status_t result = checkPid();
497 if (result != NO_ERROR) return result;
498
499 if (mHardware == 0) {
500 LOGE("mHardware is NULL, returning.");
501 return INVALID_OPERATION;
502 }
503
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800504 switch(mode) {
505 case CAMERA_RECORDING_MODE:
Wu-cheng Li988fb622009-06-23 23:37:36 +0800506 if (mSurface == 0) {
507 LOGE("setPreviewDisplay must be called before startRecordingMode.");
508 return INVALID_OPERATION;
509 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800510 return startRecordingMode();
511
512 default: // CAMERA_PREVIEW_MODE
Wu-cheng Li988fb622009-06-23 23:37:36 +0800513 if (mSurface == 0) {
Dave Sparkse7e93f92010-01-04 08:55:04 -0800514 LOGV("mSurface is not set yet.");
Wu-cheng Li988fb622009-06-23 23:37:36 +0800515 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800516 return startPreviewMode();
517 }
518}
519
520status_t CameraService::Client::startRecordingMode()
521{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800522 LOGV("startRecordingMode (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800523
524 status_t ret = UNKNOWN_ERROR;
525
526 // if preview has not been started, start preview first
527 if (!mHardware->previewEnabled()) {
528 ret = startPreviewMode();
529 if (ret != NO_ERROR) {
530 return ret;
531 }
532 }
533
534 // if recording has been enabled, nothing needs to be done
535 if (mHardware->recordingEnabled()) {
536 return NO_ERROR;
537 }
538
539 // start recording mode
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500540 ret = mHardware->startRecording();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800541 if (ret != NO_ERROR) {
542 LOGE("mHardware->startRecording() failed with status %d", ret);
543 }
544 return ret;
545}
546
Wu-cheng Li988fb622009-06-23 23:37:36 +0800547status_t CameraService::Client::setOverlay()
548{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800549 LOGV("setOverlay");
Wu-cheng Li988fb622009-06-23 23:37:36 +0800550 int w, h;
551 CameraParameters params(mHardware->getParameters());
552 params.getPreviewSize(&w, &h);
553
Benny Wong71f77152009-07-15 18:44:27 -0500554 if ( w != mOverlayW || h != mOverlayH )
555 {
556 // Force the destruction of any previous overlay
557 sp<Overlay> dummy;
558 mHardware->setOverlay( dummy );
559 mOverlayRef = 0;
560 }
561
Wu-cheng Li988fb622009-06-23 23:37:36 +0800562 status_t ret = NO_ERROR;
563 if (mSurface != 0) {
Benny Wong71f77152009-07-15 18:44:27 -0500564 if (mOverlayRef.get() == NULL) {
Dave Sparks587f7832009-10-07 19:18:20 -0700565
566 // FIXME:
567 // Surfaceflinger may hold onto the previous overlay reference for some
568 // time after we try to destroy it. retry a few times. In the future, we
569 // should make the destroy call block, or possibly specify that we can
570 // wait in the createOverlay call if the previous overlay is in the
571 // process of being destroyed.
572 for (int retry = 0; retry < 50; ++retry) {
573 mOverlayRef = mSurface->createOverlay(w, h, OVERLAY_FORMAT_DEFAULT);
574 if (mOverlayRef != NULL) break;
Dave Sparkse7e93f92010-01-04 08:55:04 -0800575 LOGW("Overlay create failed - retrying");
Dave Sparks587f7832009-10-07 19:18:20 -0700576 usleep(20000);
577 }
Benny Wong71f77152009-07-15 18:44:27 -0500578 if ( mOverlayRef.get() == NULL )
579 {
580 LOGE("Overlay Creation Failed!");
581 return -EINVAL;
582 }
583 ret = mHardware->setOverlay(new Overlay(mOverlayRef));
584 }
Wu-cheng Li988fb622009-06-23 23:37:36 +0800585 } else {
586 ret = mHardware->setOverlay(NULL);
587 }
588 if (ret != NO_ERROR) {
589 LOGE("mHardware->setOverlay() failed with status %d\n", ret);
590 }
Benny Wong71f77152009-07-15 18:44:27 -0500591
592 mOverlayW = w;
593 mOverlayH = h;
594
Wu-cheng Li988fb622009-06-23 23:37:36 +0800595 return ret;
596}
597
598status_t CameraService::Client::registerPreviewBuffers()
599{
600 int w, h;
601 CameraParameters params(mHardware->getParameters());
602 params.getPreviewSize(&w, &h);
603
604 uint32_t transform = 0;
605 if (params.getOrientation() ==
606 CameraParameters::CAMERA_ORIENTATION_PORTRAIT) {
607 LOGV("portrait mode");
608 transform = ISurface::BufferHeap::ROT_90;
609 }
610 ISurface::BufferHeap buffers(w, h, w, h,
611 PIXEL_FORMAT_YCbCr_420_SP,
612 transform,
613 0,
614 mHardware->getPreviewHeap());
615
616 status_t ret = mSurface->registerBuffers(buffers);
617 if (ret != NO_ERROR) {
618 LOGE("registerBuffers failed with status %d", ret);
619 }
620 return ret;
621}
622
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800623status_t CameraService::Client::startPreviewMode()
624{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800625 LOGV("startPreviewMode (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800626
627 // if preview has been enabled, nothing needs to be done
628 if (mHardware->previewEnabled()) {
629 return NO_ERROR;
630 }
631
632 // start preview mode
633#if DEBUG_DUMP_PREVIEW_FRAME_TO_FILE
634 debug_frame_cnt = 0;
635#endif
Wu-cheng Li988fb622009-06-23 23:37:36 +0800636 status_t ret = NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800637
638 if (mUseOverlay) {
Wu-cheng Li988fb622009-06-23 23:37:36 +0800639 // If preview display has been set, set overlay now.
640 if (mSurface != 0) {
641 ret = setOverlay();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800642 }
Wu-cheng Li988fb622009-06-23 23:37:36 +0800643 if (ret != NO_ERROR) return ret;
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500644 ret = mHardware->startPreview();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800645 } else {
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500646 mHardware->enableMsgType(CAMERA_MSG_PREVIEW_FRAME);
647 ret = mHardware->startPreview();
Wu-cheng Li988fb622009-06-23 23:37:36 +0800648 if (ret != NO_ERROR) return ret;
649 // If preview display has been set, register preview buffers now.
650 if (mSurface != 0) {
651 // Unregister here because the surface registered with raw heap.
652 mSurface->unregisterBuffers();
653 ret = registerPreviewBuffers();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800654 }
655 }
656 return ret;
657}
658
659status_t CameraService::Client::startPreview()
660{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800661 LOGV("startPreview (pid %d)", getCallingPid());
Wu-cheng Lie6a550d2009-09-28 16:14:58 -0700662
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800663 return startCameraMode(CAMERA_PREVIEW_MODE);
664}
665
666status_t CameraService::Client::startRecording()
667{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800668 LOGV("startRecording (pid %d)", getCallingPid());
Chih-Chung Changd98c5162009-06-22 16:03:41 +0800669
Jason Sams78b877e2009-03-24 20:21:36 -0700670 if (mMediaPlayerBeep.get() != NULL) {
Eric Laurent059b4132009-11-27 05:07:55 -0800671 // do not play record jingle if stream volume is 0
672 // (typically because ringer mode is silent).
673 int index;
674 AudioSystem::getStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE, &index);
675 if (index != 0) {
676 mMediaPlayerBeep->seekTo(0);
677 mMediaPlayerBeep->start();
678 }
Jason Sams78b877e2009-03-24 20:21:36 -0700679 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500680
681 mHardware->enableMsgType(CAMERA_MSG_VIDEO_FRAME);
682
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800683 return startCameraMode(CAMERA_RECORDING_MODE);
684}
685
686// stop preview mode
687void CameraService::Client::stopPreview()
688{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800689 LOGV("stopPreview (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800690
Dave Sparksff0f38e2009-11-10 17:08:08 -0800691 // hold main lock during state transition
692 {
693 Mutex::Autolock lock(mLock);
694 if (checkPid() != NO_ERROR) return;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800695
Dave Sparksff0f38e2009-11-10 17:08:08 -0800696 if (mHardware == 0) {
697 LOGE("mHardware is NULL, returning.");
698 return;
699 }
700
701 mHardware->stopPreview();
702 mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
Dave Sparkse7e93f92010-01-04 08:55:04 -0800703 LOGV("stopPreview(), hardware stopped OK");
Dave Sparksff0f38e2009-11-10 17:08:08 -0800704
705 if (mSurface != 0 && !mUseOverlay) {
706 mSurface->unregisterBuffers();
707 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800708 }
709
Dave Sparksff0f38e2009-11-10 17:08:08 -0800710 // hold preview buffer lock
711 {
712 Mutex::Autolock lock(mPreviewLock);
713 mPreviewBuffer.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800714 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800715}
716
717// stop recording mode
718void CameraService::Client::stopRecording()
719{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800720 LOGV("stopRecording (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800721
Dave Sparksff0f38e2009-11-10 17:08:08 -0800722 // hold main lock during state transition
723 {
724 Mutex::Autolock lock(mLock);
725 if (checkPid() != NO_ERROR) return;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800726
Dave Sparksff0f38e2009-11-10 17:08:08 -0800727 if (mHardware == 0) {
728 LOGE("mHardware is NULL, returning.");
729 return;
730 }
731
732 if (mMediaPlayerBeep.get() != NULL) {
733 mMediaPlayerBeep->seekTo(0);
734 mMediaPlayerBeep->start();
735 }
736
737 mHardware->stopRecording();
738 mHardware->disableMsgType(CAMERA_MSG_VIDEO_FRAME);
Dave Sparkse7e93f92010-01-04 08:55:04 -0800739 LOGV("stopRecording(), hardware stopped OK");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800740 }
741
Dave Sparksff0f38e2009-11-10 17:08:08 -0800742 // hold preview buffer lock
743 {
744 Mutex::Autolock lock(mPreviewLock);
745 mPreviewBuffer.clear();
Jason Sams78b877e2009-03-24 20:21:36 -0700746 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800747}
748
749// release a recording frame
750void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem)
751{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800752 Mutex::Autolock lock(mLock);
753 if (checkPid() != NO_ERROR) return;
754
755 if (mHardware == 0) {
756 LOGE("mHardware is NULL, returning.");
757 return;
758 }
759
760 mHardware->releaseRecordingFrame(mem);
761}
762
763bool CameraService::Client::previewEnabled()
764{
765 Mutex::Autolock lock(mLock);
766 if (mHardware == 0) return false;
767 return mHardware->previewEnabled();
768}
769
770bool CameraService::Client::recordingEnabled()
771{
772 Mutex::Autolock lock(mLock);
773 if (mHardware == 0) return false;
774 return mHardware->recordingEnabled();
775}
776
777// Safely retrieves a strong pointer to the client during a hardware callback.
778sp<CameraService::Client> CameraService::Client::getClientFromCookie(void* user)
779{
780 sp<Client> client = 0;
781 CameraService *service = static_cast<CameraService*>(user);
782 if (service != NULL) {
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +0800783 Mutex::Autolock ourLock(service->mServiceLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800784 if (service->mClient != 0) {
785 client = service->mClient.promote();
786 if (client == 0) {
787 LOGE("getClientFromCookie: client appears to have died");
788 service->mClient.clear();
789 }
790 } else {
791 LOGE("getClientFromCookie: got callback but client was NULL");
792 }
793 }
794 return client;
795}
796
797
798#if DEBUG_DUMP_JPEG_SNAPSHOT_TO_FILE || \
799 DEBUG_DUMP_YUV_SNAPSHOT_TO_FILE || \
800 DEBUG_DUMP_PREVIEW_FRAME_TO_FILE
801static void dump_to_file(const char *fname,
802 uint8_t *buf, uint32_t size)
803{
804 int nw, cnt = 0;
805 uint32_t written = 0;
806
Joe Onorato51632e82010-01-07 21:48:32 -0500807 LOGV("opening file [%s]\n", fname);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800808 int fd = open(fname, O_RDWR | O_CREAT);
809 if (fd < 0) {
810 LOGE("failed to create file [%s]: %s", fname, strerror(errno));
811 return;
812 }
813
Joe Onorato51632e82010-01-07 21:48:32 -0500814 LOGV("writing %d bytes to file [%s]\n", size, fname);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800815 while (written < size) {
816 nw = ::write(fd,
817 buf + written,
818 size - written);
819 if (nw < 0) {
820 LOGE("failed to write to file [%s]: %s",
821 fname, strerror(errno));
822 break;
823 }
824 written += nw;
825 cnt++;
826 }
Joe Onorato51632e82010-01-07 21:48:32 -0500827 LOGV("done writing %d bytes to file [%s] in %d passes\n",
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800828 size, fname, cnt);
829 ::close(fd);
830}
831#endif
832
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800833status_t CameraService::Client::autoFocus()
834{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800835 LOGV("autoFocus (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800836
837 Mutex::Autolock lock(mLock);
838 status_t result = checkPid();
839 if (result != NO_ERROR) return result;
840
841 if (mHardware == 0) {
842 LOGE("mHardware is NULL, returning.");
843 return INVALID_OPERATION;
844 }
845
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500846 return mHardware->autoFocus();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800847}
848
Chih-Chung Chang00900eb2009-09-15 14:51:56 +0800849status_t CameraService::Client::cancelAutoFocus()
850{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800851 LOGV("cancelAutoFocus (pid %d)", getCallingPid());
Chih-Chung Chang00900eb2009-09-15 14:51:56 +0800852
853 Mutex::Autolock lock(mLock);
854 status_t result = checkPid();
855 if (result != NO_ERROR) return result;
856
857 if (mHardware == 0) {
858 LOGE("mHardware is NULL, returning.");
859 return INVALID_OPERATION;
860 }
861
862 return mHardware->cancelAutoFocus();
863}
864
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800865// take a picture - image is returned in callback
866status_t CameraService::Client::takePicture()
867{
Dave Sparkse7e93f92010-01-04 08:55:04 -0800868 LOGV("takePicture (pid %d)", getCallingPid());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800869
870 Mutex::Autolock lock(mLock);
871 status_t result = checkPid();
872 if (result != NO_ERROR) return result;
873
874 if (mHardware == 0) {
875 LOGE("mHardware is NULL, returning.");
876 return INVALID_OPERATION;
877 }
878
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500879 mHardware->enableMsgType(CAMERA_MSG_SHUTTER |
880 CAMERA_MSG_POSTVIEW_FRAME |
881 CAMERA_MSG_RAW_IMAGE |
882 CAMERA_MSG_COMPRESSED_IMAGE);
883
884 return mHardware->takePicture();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800885}
886
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500887// snapshot taken
Wu-cheng Li986e0dc2009-10-23 17:39:46 +0800888void CameraService::Client::handleShutter(
889 image_rect_type *size // The width and height of yuv picture for
890 // registerBuffer. If this is NULL, use the picture
891 // size from parameters.
892)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800893{
Wu-cheng Liaab44b82009-03-24 20:39:09 -0700894 // Play shutter sound.
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500895 if (mMediaPlayerClick.get() != NULL) {
Eric Laurent059b4132009-11-27 05:07:55 -0800896 // do not play shutter sound if stream volume is 0
897 // (typically because ringer mode is silent).
898 int index;
899 AudioSystem::getStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE, &index);
900 if (index != 0) {
901 mMediaPlayerClick->seekTo(0);
902 mMediaPlayerClick->start();
903 }
Wu-cheng Liaab44b82009-03-24 20:39:09 -0700904 }
905
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800906 // Screen goes black after the buffer is unregistered.
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500907 if (mSurface != 0 && !mUseOverlay) {
908 mSurface->unregisterBuffers();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800909 }
910
Dave Sparks393eb792009-10-15 10:02:22 -0700911 sp<ICameraClient> c = mCameraClient;
912 if (c != NULL) {
913 c->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0);
914 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500915 mHardware->disableMsgType(CAMERA_MSG_SHUTTER);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800916
917 // It takes some time before yuvPicture callback to be called.
918 // Register the buffer for raw image here to reduce latency.
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500919 if (mSurface != 0 && !mUseOverlay) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800920 int w, h;
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500921 CameraParameters params(mHardware->getParameters());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800922 uint32_t transform = 0;
923 if (params.getOrientation() == CameraParameters::CAMERA_ORIENTATION_PORTRAIT) {
924 LOGV("portrait mode");
925 transform = ISurface::BufferHeap::ROT_90;
926 }
Wu-cheng Li986e0dc2009-10-23 17:39:46 +0800927
928 if (size == NULL) {
929 params.getPictureSize(&w, &h);
930 } else {
931 w = size->width;
932 h = size->height;
933 w &= ~1;
934 h &= ~1;
Dave Sparkse7e93f92010-01-04 08:55:04 -0800935 LOGV("Snapshot image width=%d, height=%d", w, h);
Wu-cheng Li986e0dc2009-10-23 17:39:46 +0800936 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800937 ISurface::BufferHeap buffers(w, h, w, h,
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500938 PIXEL_FORMAT_YCbCr_420_SP, transform, 0, mHardware->getRawHeap());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800939
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500940 mSurface->registerBuffers(buffers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800941 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800942}
943
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500944// preview callback - frame buffer update
945void CameraService::Client::handlePreviewData(const sp<IMemory>& mem)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800946{
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500947 ssize_t offset;
948 size_t size;
949 sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
950
951#if DEBUG_HEAP_LEAKS && 0 // debugging
952 if (gWeakHeap == NULL) {
953 if (gWeakHeap != heap) {
Dave Sparkse7e93f92010-01-04 08:55:04 -0800954 LOGV("SETTING PREVIEW HEAP");
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500955 heap->trackMe(true, true);
956 gWeakHeap = heap;
957 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800958 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500959#endif
960#if DEBUG_DUMP_PREVIEW_FRAME_TO_FILE
961 {
962 if (debug_frame_cnt++ == DEBUG_DUMP_PREVIEW_FRAME_TO_FILE) {
963 dump_to_file("/data/preview.yuv",
964 (uint8_t *)heap->base() + offset, size);
965 }
966 }
967#endif
968
969 if (!mUseOverlay)
970 {
971 Mutex::Autolock surfaceLock(mSurfaceLock);
972 if (mSurface != NULL) {
973 mSurface->postBuffer(offset);
974 }
975 }
976
Dave Sparks393eb792009-10-15 10:02:22 -0700977 // local copy of the callback flags
978 int flags = mPreviewCallbackFlag;
979
980 // is callback enabled?
981 if (!(flags & FRAME_CALLBACK_FLAG_ENABLE_MASK)) {
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500982 // If the enable bit is off, the copy-out and one-shot bits are ignored
983 LOGV("frame callback is diabled");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800984 return;
985 }
986
Dave Sparks393eb792009-10-15 10:02:22 -0700987 // hold a strong pointer to the client
988 sp<ICameraClient> c = mCameraClient;
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500989
Dave Sparks393eb792009-10-15 10:02:22 -0700990 // clear callback flags if no client or one-shot mode
991 if ((c == NULL) || (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ONE_SHOT_MASK)) {
992 LOGV("Disable preview callback");
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500993 mPreviewCallbackFlag &= ~(FRAME_CALLBACK_FLAG_ONE_SHOT_MASK |
994 FRAME_CALLBACK_FLAG_COPY_OUT_MASK |
995 FRAME_CALLBACK_FLAG_ENABLE_MASK);
Dave Sparks393eb792009-10-15 10:02:22 -0700996 // TODO: Shouldn't we use this API for non-overlay hardware as well?
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500997 if (mUseOverlay)
998 mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
999 }
Dave Sparks393eb792009-10-15 10:02:22 -07001000
1001 // Is the received frame copied out or not?
1002 if (flags & FRAME_CALLBACK_FLAG_COPY_OUT_MASK) {
1003 LOGV("frame is copied");
1004 copyFrameAndPostCopiedFrame(c, heap, offset, size);
1005 } else {
1006 LOGV("frame is forwarded");
1007 c->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem);
1008 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001009}
1010
1011// picture callback - postview image ready
1012void CameraService::Client::handlePostview(const sp<IMemory>& mem)
1013{
1014#if DEBUG_DUMP_POSTVIEW_SNAPSHOT_TO_FILE // for testing pursposes only
1015 {
1016 ssize_t offset;
1017 size_t size;
1018 sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
1019 dump_to_file("/data/postview.yuv",
1020 (uint8_t *)heap->base() + offset, size);
1021 }
1022#endif
1023
Dave Sparks393eb792009-10-15 10:02:22 -07001024 sp<ICameraClient> c = mCameraClient;
1025 if (c != NULL) {
1026 c->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem);
1027 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001028 mHardware->disableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
1029}
1030
1031// picture callback - raw image ready
1032void CameraService::Client::handleRawPicture(const sp<IMemory>& mem)
1033{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001034 ssize_t offset;
1035 size_t size;
1036 sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
1037#if DEBUG_HEAP_LEAKS && 0 // debugging
1038 gWeakHeap = heap; // debugging
1039#endif
1040
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001041 //LOGV("handleRawPicture(%d, %d)", offset, size);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001042#if DEBUG_DUMP_YUV_SNAPSHOT_TO_FILE // for testing pursposes only
1043 dump_to_file("/data/photo.yuv",
1044 (uint8_t *)heap->base() + offset, size);
1045#endif
1046
1047 // Put the YUV version of the snapshot in the preview display.
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001048 if (mSurface != 0 && !mUseOverlay) {
1049 mSurface->postBuffer(offset);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001050 }
1051
Dave Sparks393eb792009-10-15 10:02:22 -07001052 sp<ICameraClient> c = mCameraClient;
1053 if (c != NULL) {
1054 c->dataCallback(CAMERA_MSG_RAW_IMAGE, mem);
1055 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001056 mHardware->disableMsgType(CAMERA_MSG_RAW_IMAGE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001057}
1058
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001059// picture callback - compressed picture ready
1060void CameraService::Client::handleCompressedPicture(const sp<IMemory>& mem)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001061{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001062#if DEBUG_DUMP_JPEG_SNAPSHOT_TO_FILE // for testing pursposes only
1063 {
1064 ssize_t offset;
1065 size_t size;
1066 sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
1067 dump_to_file("/data/photo.jpg",
1068 (uint8_t *)heap->base() + offset, size);
1069 }
1070#endif
1071
Dave Sparks393eb792009-10-15 10:02:22 -07001072 sp<ICameraClient> c = mCameraClient;
1073 if (c != NULL) {
1074 c->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem);
1075 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001076 mHardware->disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001077}
1078
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001079void CameraService::Client::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2, void* user)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001080{
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001081 LOGV("notifyCallback(%d)", msgType);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001082
1083 sp<Client> client = getClientFromCookie(user);
1084 if (client == 0) {
1085 return;
1086 }
1087
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001088 switch (msgType) {
1089 case CAMERA_MSG_SHUTTER:
Wu-cheng Li986e0dc2009-10-23 17:39:46 +08001090 // ext1 is the dimension of the yuv picture.
1091 client->handleShutter((image_rect_type *)ext1);
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001092 break;
1093 default:
Dave Sparks393eb792009-10-15 10:02:22 -07001094 sp<ICameraClient> c = client->mCameraClient;
1095 if (c != NULL) {
1096 c->notifyCallback(msgType, ext1, ext2);
1097 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001098 break;
1099 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001100
1101#if DEBUG_CLIENT_REFERENCES
1102 if (client->getStrongCount() == 1) {
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001103 LOGE("++++++++++++++++ (NOTIFY CALLBACK) THIS WILL CAUSE A LOCKUP!");
1104 client->printRefs();
1105 }
1106#endif
1107}
1108
1109void CameraService::Client::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, void* user)
1110{
1111 LOGV("dataCallback(%d)", msgType);
1112
1113 sp<Client> client = getClientFromCookie(user);
1114 if (client == 0) {
1115 return;
1116 }
1117
Dave Sparks393eb792009-10-15 10:02:22 -07001118 sp<ICameraClient> c = client->mCameraClient;
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001119 if (dataPtr == NULL) {
1120 LOGE("Null data returned in data callback");
Dave Sparks393eb792009-10-15 10:02:22 -07001121 if (c != NULL) {
1122 c->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0);
1123 c->dataCallback(msgType, NULL);
1124 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001125 return;
1126 }
1127
1128 switch (msgType) {
1129 case CAMERA_MSG_PREVIEW_FRAME:
1130 client->handlePreviewData(dataPtr);
1131 break;
1132 case CAMERA_MSG_POSTVIEW_FRAME:
1133 client->handlePostview(dataPtr);
1134 break;
1135 case CAMERA_MSG_RAW_IMAGE:
1136 client->handleRawPicture(dataPtr);
1137 break;
1138 case CAMERA_MSG_COMPRESSED_IMAGE:
1139 client->handleCompressedPicture(dataPtr);
1140 break;
1141 default:
Dave Sparks393eb792009-10-15 10:02:22 -07001142 if (c != NULL) {
1143 c->dataCallback(msgType, dataPtr);
1144 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001145 break;
1146 }
1147
1148#if DEBUG_CLIENT_REFERENCES
1149 if (client->getStrongCount() == 1) {
1150 LOGE("++++++++++++++++ (DATA CALLBACK) THIS WILL CAUSE A LOCKUP!");
1151 client->printRefs();
1152 }
1153#endif
1154}
1155
1156void CameraService::Client::dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType,
1157 const sp<IMemory>& dataPtr, void* user)
1158{
1159 LOGV("dataCallbackTimestamp(%d)", msgType);
1160
1161 sp<Client> client = getClientFromCookie(user);
1162 if (client == 0) {
1163 return;
1164 }
Dave Sparks393eb792009-10-15 10:02:22 -07001165 sp<ICameraClient> c = client->mCameraClient;
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001166
1167 if (dataPtr == NULL) {
1168 LOGE("Null data returned in data with timestamp callback");
Dave Sparks393eb792009-10-15 10:02:22 -07001169 if (c != NULL) {
1170 c->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0);
1171 c->dataCallbackTimestamp(0, msgType, NULL);
1172 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001173 return;
1174 }
1175
Dave Sparks393eb792009-10-15 10:02:22 -07001176 if (c != NULL) {
1177 c->dataCallbackTimestamp(timestamp, msgType, dataPtr);
1178 }
Benny Wong4c8fb0a2009-08-12 12:01:27 -05001179
1180#if DEBUG_CLIENT_REFERENCES
1181 if (client->getStrongCount() == 1) {
1182 LOGE("++++++++++++++++ (DATA CALLBACK TIMESTAMP) THIS WILL CAUSE A LOCKUP!");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001183 client->printRefs();
1184 }
1185#endif
1186}
1187
1188// set preview/capture parameters - key/value pairs
1189status_t CameraService::Client::setParameters(const String8& params)
1190{
Joe Onorato51632e82010-01-07 21:48:32 -05001191 LOGV("setParameters(%s)", params.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001192
1193 Mutex::Autolock lock(mLock);
1194 status_t result = checkPid();
1195 if (result != NO_ERROR) return result;
1196
1197 if (mHardware == 0) {
1198 LOGE("mHardware is NULL, returning.");
1199 return INVALID_OPERATION;
1200 }
1201
1202 CameraParameters p(params);
James Dong102f7772009-09-13 17:10:24 -07001203 return mHardware->setParameters(p);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001204}
1205
1206// get preview/capture parameters - key/value pairs
1207String8 CameraService::Client::getParameters() const
1208{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001209 Mutex::Autolock lock(mLock);
1210
1211 if (mHardware == 0) {
1212 LOGE("mHardware is NULL, returning.");
1213 return String8();
1214 }
1215
Wu-cheng Li81d763f2009-04-22 16:21:26 +08001216 String8 params(mHardware->getParameters().flatten());
Joe Onorato51632e82010-01-07 21:48:32 -05001217 LOGV("getParameters(%s)", params.string());
Wu-cheng Li81d763f2009-04-22 16:21:26 +08001218 return params;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001219}
1220
Wu-cheng Lie6a550d2009-09-28 16:14:58 -07001221status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
1222{
Dave Sparkse7e93f92010-01-04 08:55:04 -08001223 LOGV("sendCommand (pid %d)", getCallingPid());
Wu-cheng Lie6a550d2009-09-28 16:14:58 -07001224 Mutex::Autolock lock(mLock);
1225 status_t result = checkPid();
1226 if (result != NO_ERROR) return result;
1227
1228 if (mHardware == 0) {
1229 LOGE("mHardware is NULL, returning.");
1230 return INVALID_OPERATION;
1231 }
1232
1233 return mHardware->sendCommand(cmd, arg1, arg2);
1234}
1235
Dave Sparks393eb792009-10-15 10:02:22 -07001236void CameraService::Client::copyFrameAndPostCopiedFrame(const sp<ICameraClient>& client,
1237 const sp<IMemoryHeap>& heap, size_t offset, size_t size)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001238{
1239 LOGV("copyFrameAndPostCopiedFrame");
1240 // It is necessary to copy out of pmem before sending this to
1241 // the callback. For efficiency, reuse the same MemoryHeapBase
1242 // provided it's big enough. Don't allocate the memory or
1243 // perform the copy if there's no callback.
Dave Sparks23c21ba2009-11-06 11:47:13 -08001244
Dave Sparksff0f38e2009-11-10 17:08:08 -08001245 // hold the preview lock while we grab a reference to the preview buffer
Dave Sparks23c21ba2009-11-06 11:47:13 -08001246 sp<MemoryHeapBase> previewBuffer;
1247 {
Dave Sparksff0f38e2009-11-10 17:08:08 -08001248 Mutex::Autolock lock(mPreviewLock);
Dave Sparks23c21ba2009-11-06 11:47:13 -08001249 if (mPreviewBuffer == 0) {
1250 mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
1251 } else if (size > mPreviewBuffer->virtualSize()) {
1252 mPreviewBuffer.clear();
1253 mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
1254 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001255 if (mPreviewBuffer == 0) {
1256 LOGE("failed to allocate space for preview buffer");
1257 return;
1258 }
Dave Sparks23c21ba2009-11-06 11:47:13 -08001259 previewBuffer = mPreviewBuffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001260 }
Dave Sparks23c21ba2009-11-06 11:47:13 -08001261 memcpy(previewBuffer->base(),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001262 (uint8_t *)heap->base() + offset, size);
1263
Dave Sparks23c21ba2009-11-06 11:47:13 -08001264 sp<MemoryBase> frame = new MemoryBase(previewBuffer, 0, size);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001265 if (frame == 0) {
1266 LOGE("failed to allocate space for frame callback");
1267 return;
1268 }
Dave Sparks393eb792009-10-15 10:02:22 -07001269 client->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001270}
1271
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001272status_t CameraService::dump(int fd, const Vector<String16>& args)
1273{
1274 const size_t SIZE = 256;
1275 char buffer[SIZE];
1276 String8 result;
1277 if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
1278 snprintf(buffer, SIZE, "Permission Denial: "
1279 "can't dump CameraService from pid=%d, uid=%d\n",
Chih-Chung Changd98c5162009-06-22 16:03:41 +08001280 getCallingPid(),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001281 IPCThreadState::self()->getCallingUid());
1282 result.append(buffer);
1283 write(fd, result.string(), result.size());
1284 } else {
Chih-Chung Changd2d6bc72009-06-24 19:59:31 +08001285 AutoMutex lock(&mServiceLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001286 if (mClient != 0) {
1287 sp<Client> currentClient = mClient.promote();
1288 sprintf(buffer, "Client (%p) PID: %d\n",
1289 currentClient->getCameraClient()->asBinder().get(),
1290 currentClient->mClientPid);
1291 result.append(buffer);
1292 write(fd, result.string(), result.size());
1293 currentClient->mHardware->dump(fd, args);
1294 } else {
1295 result.append("No camera client yet.\n");
1296 write(fd, result.string(), result.size());
1297 }
1298 }
1299 return NO_ERROR;
1300}
1301
1302
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001303status_t CameraService::onTransact(
1304 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1305{
1306 // permission checks...
1307 switch (code) {
1308 case BnCameraService::CONNECT:
1309 IPCThreadState* ipc = IPCThreadState::self();
1310 const int pid = ipc->getCallingPid();
1311 const int self_pid = getpid();
1312 if (pid != self_pid) {
1313 // we're called from a different process, do the real check
1314 if (!checkCallingPermission(
1315 String16("android.permission.CAMERA")))
1316 {
1317 const int uid = ipc->getCallingUid();
1318 LOGE("Permission Denial: "
1319 "can't use the camera pid=%d, uid=%d", pid, uid);
1320 return PERMISSION_DENIED;
1321 }
1322 }
1323 break;
1324 }
1325
1326 status_t err = BnCameraService::onTransact(code, data, reply, flags);
1327
Dave Sparks998b3292009-05-20 20:02:59 -07001328#if DEBUG_HEAP_LEAKS
Joe Onorato51632e82010-01-07 21:48:32 -05001329 LOGV("+++ onTransact err %d code %d", err, code);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001330
1331 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
1332 // the 'service' command interrogates this binder for its name, and then supplies it
1333 // even for the debugging commands. that means we need to check for it here, using
1334 // ISurfaceComposer (since we delegated the INTERFACE_TRANSACTION handling to
1335 // BnSurfaceComposer before falling through to this code).
1336
Joe Onorato51632e82010-01-07 21:48:32 -05001337 LOGV("+++ onTransact code %d", code);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001338
1339 CHECK_INTERFACE(ICameraService, data, reply);
1340
1341 switch(code) {
1342 case 1000:
1343 {
1344 if (gWeakHeap != 0) {
1345 sp<IMemoryHeap> h = gWeakHeap.promote();
1346 IMemoryHeap *p = gWeakHeap.unsafe_get();
Joe Onorato51632e82010-01-07 21:48:32 -05001347 LOGV("CHECKING WEAK REFERENCE %p (%p)", h.get(), p);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001348 if (h != 0)
1349 h->printRefs();
1350 bool attempt_to_delete = data.readInt32() == 1;
1351 if (attempt_to_delete) {
1352 // NOT SAFE!
Joe Onorato51632e82010-01-07 21:48:32 -05001353 LOGV("DELETING WEAK REFERENCE %p (%p)", h.get(), p);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001354 if (p) delete p;
1355 }
1356 return NO_ERROR;
1357 }
1358 }
1359 break;
1360 default:
1361 break;
1362 }
1363 }
Dave Sparks998b3292009-05-20 20:02:59 -07001364#endif // DEBUG_HEAP_LEAKS
Dave Sparksfec880d2009-05-21 09:18:18 -07001365
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001366 return err;
1367}
1368
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001369}; // namespace android