2008-10-21 14:00:00 +00:00
|
|
|
/*
|
|
|
|
**
|
2008-12-18 02:05:43 +00:00
|
|
|
** Copyright (C) 2008, The Android Open Source Project
|
|
|
|
** Copyright (C) 2008 HTC Inc.
|
2008-10-21 14:00:00 +00:00
|
|
|
**
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
|
|
|
|
#define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
|
|
|
|
|
|
|
|
#include <ui/ICameraService.h>
|
|
|
|
#include <ui/CameraHardwareInterface.h>
|
2008-12-18 02:05:43 +00:00
|
|
|
#include <ui/Camera.h>
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class android::MemoryHeapBase;
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
|
|
|
|
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
|
|
|
|
|
|
|
|
// When enabled, this feature allows you to send an event to the CameraService
|
|
|
|
// so that you can cause all references to the heap object gWeakHeap, defined
|
|
|
|
// below, to be printed. You will also need to set DEBUG_REFS=1 and
|
2008-12-18 02:05:43 +00:00
|
|
|
// DEBUG_REFS_ENABLED_BY_DEFAULT=0 in libutils/RefBase.cpp. You just have to
|
2008-10-21 14:00:00 +00:00
|
|
|
// set gWeakHeap to the appropriate heap you want to track.
|
|
|
|
|
|
|
|
#define DEBUG_HEAP_LEAKS 0
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CameraService : public BnCameraService
|
|
|
|
{
|
|
|
|
class Client;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void instantiate();
|
|
|
|
|
|
|
|
// ICameraService interface
|
|
|
|
virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient);
|
|
|
|
|
|
|
|
virtual status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
void removeClient(const sp<ICameraClient>& cameraClient);
|
|
|
|
|
|
|
|
#if DEBUG_HEAP_LEAKS
|
|
|
|
virtual status_t onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Client : public BnCamera {
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void disconnect();
|
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
// connect new client with existing camera remote
|
|
|
|
virtual status_t connect(const sp<ICameraClient>& client);
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
// prevent other processes from using this ICamera interface
|
|
|
|
virtual status_t lock();
|
|
|
|
|
|
|
|
// allow other processes to use this ICamera interface
|
|
|
|
virtual status_t unlock();
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
// pass the buffered ISurface to the camera service
|
|
|
|
virtual status_t setPreviewDisplay(const sp<ISurface>& surface);
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
// set the frame callback flag to affect how the received frames from
|
|
|
|
// preview are handled.
|
|
|
|
virtual void setFrameCallbackFlag(int frame_callback_flag);
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
// start preview mode, must call setPreviewDisplay first
|
|
|
|
virtual status_t startPreview();
|
|
|
|
|
|
|
|
// stop preview mode
|
|
|
|
virtual void stopPreview();
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
// get preview state
|
|
|
|
virtual bool previewEnabled();
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
// auto focus
|
|
|
|
virtual status_t autoFocus();
|
|
|
|
|
|
|
|
// take a picture - returns an IMemory (ref-counted mmap)
|
|
|
|
virtual status_t takePicture();
|
|
|
|
|
|
|
|
// set preview/capture parameters - key/value pairs
|
|
|
|
virtual status_t setParameters(const String8& params);
|
|
|
|
|
|
|
|
// get preview/capture parameters - key/value pairs
|
|
|
|
virtual String8 getParameters() const;
|
|
|
|
|
|
|
|
// our client...
|
|
|
|
const sp<ICameraClient>& getCameraClient() const { return mCameraClient; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class CameraService;
|
2009-01-10 01:51:23 +00:00
|
|
|
Client(const sp<CameraService>& cameraService,
|
|
|
|
const sp<ICameraClient>& cameraClient,
|
|
|
|
pid_t clientPid);
|
2008-10-21 14:00:00 +00:00
|
|
|
Client();
|
|
|
|
virtual ~Client();
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
status_t checkPid();
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
static void previewCallback(const sp<IMemory>& mem, void* user);
|
|
|
|
static void shutterCallback(void *user);
|
|
|
|
static void yuvPictureCallback(const sp<IMemory>& mem, void* user);
|
|
|
|
static void jpegPictureCallback(const sp<IMemory>& mem, void* user);
|
|
|
|
static void autoFocusCallback(bool focused, void* user);
|
|
|
|
static sp<Client> getClientFromCookie(void* user);
|
|
|
|
|
|
|
|
void postShutter();
|
|
|
|
void postRaw(const sp<IMemory>& mem);
|
|
|
|
void postJpeg(const sp<IMemory>& mem);
|
|
|
|
void postFrame(const sp<IMemory>& mem);
|
2008-12-18 02:05:43 +00:00
|
|
|
void copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size);
|
2008-10-21 14:00:00 +00:00
|
|
|
void postError(status_t error);
|
|
|
|
void postAutoFocus(bool focused);
|
|
|
|
|
|
|
|
// Ensures atomicity among the public methods
|
|
|
|
mutable Mutex mLock;
|
|
|
|
// mSurfaceLock synchronizes access to mSurface between
|
|
|
|
// setPreviewSurface() and postFrame(). Note that among
|
2008-12-18 02:05:43 +00:00
|
|
|
// the public methods, all accesses to mSurface are
|
2008-10-21 14:00:00 +00:00
|
|
|
// syncrhonized by mLock. However, postFrame() is called
|
2008-12-18 02:05:43 +00:00
|
|
|
// by the CameraHardwareInterface callback, and needs to
|
2008-10-21 14:00:00 +00:00
|
|
|
// access mSurface. It cannot hold mLock, however, because
|
|
|
|
// stopPreview() may be holding that lock while attempting
|
2009-01-10 01:51:23 +00:00
|
|
|
// to stop preview, and stopPreview itself will block waiting
|
2008-12-18 02:05:43 +00:00
|
|
|
// for a callback from CameraHardwareInterface. If this
|
2008-10-21 14:00:00 +00:00
|
|
|
// happens, it will cause a deadlock.
|
|
|
|
mutable Mutex mSurfaceLock;
|
|
|
|
mutable Condition mReady;
|
|
|
|
sp<CameraService> mCameraService;
|
|
|
|
sp<ISurface> mSurface;
|
|
|
|
sp<MemoryHeapBase> mPreviewBuffer;
|
2008-12-18 02:05:43 +00:00
|
|
|
int mFrameCallbackFlag;
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
// these are immutable once the object is created,
|
|
|
|
// they don't need to be protected by a lock
|
|
|
|
sp<ICameraClient> mCameraClient;
|
|
|
|
sp<CameraHardwareInterface> mHardware;
|
2009-01-10 01:51:23 +00:00
|
|
|
pid_t mClientPid;
|
2008-10-21 14:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CameraService();
|
|
|
|
virtual ~CameraService();
|
|
|
|
|
|
|
|
mutable Mutex mLock;
|
|
|
|
wp<Client> mClient;
|
|
|
|
|
|
|
|
#if DEBUG_HEAP_LEAKS
|
|
|
|
wp<IMemoryHeap> gWeakHeap;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif
|