2008-10-21 14:00:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2008-12-18 02:05:43 +00:00
|
|
|
* 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_HARDWARE_CAMERA_H
|
|
|
|
#define ANDROID_HARDWARE_CAMERA_H
|
|
|
|
|
|
|
|
#include <ui/ICameraClient.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
/*
|
2009-02-10 23:44:00 +00:00
|
|
|
* A set of bit masks for specifying how the received preview frames are
|
|
|
|
* handled before the previewCallback() call.
|
2008-12-18 02:05:43 +00:00
|
|
|
*
|
|
|
|
* The least significant 3 bits of an "int" value are used for this purpose:
|
|
|
|
*
|
|
|
|
* ..... 0 0 0
|
|
|
|
* ^ ^ ^
|
|
|
|
* | | |---------> determine whether the callback is enabled or not
|
|
|
|
* | |-----------> determine whether the callback is one-shot or not
|
|
|
|
* |-------------> determine whether the frame is copied out or not
|
|
|
|
*
|
2009-02-10 23:44:00 +00:00
|
|
|
* WARNING:
|
|
|
|
* When a frame is sent directly without copying, it is the frame receiver's
|
|
|
|
* responsiblity to make sure that the frame data won't get corrupted by
|
|
|
|
* subsequent preview frames filled by the camera. This flag is recommended
|
|
|
|
* only when copying out data brings significant performance price and the
|
|
|
|
* handling/processing of the received frame data is always faster than
|
|
|
|
* the preview frame rate so that data corruption won't occur.
|
|
|
|
*
|
2008-12-18 02:05:43 +00:00
|
|
|
* For instance,
|
|
|
|
* 1. 0x00 disables the callback. In this case, copy out and one shot bits
|
|
|
|
* are ignored.
|
2009-02-10 23:44:00 +00:00
|
|
|
* 2. 0x01 enables a callback without copying out the received frames. A
|
2008-12-18 02:05:43 +00:00
|
|
|
* typical use case is the Camcorder application to avoid making costly
|
|
|
|
* frame copies.
|
|
|
|
* 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
|
|
|
|
* use case is the Camera application.
|
|
|
|
* 4. 0x07 is enabling a callback with frame copied out only once. A typical use
|
|
|
|
* case is the Barcode scanner application.
|
|
|
|
*/
|
|
|
|
#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01
|
|
|
|
#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02
|
|
|
|
#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04
|
|
|
|
|
|
|
|
// Typical use cases
|
|
|
|
#define FRAME_CALLBACK_FLAG_NOOP 0x00
|
|
|
|
#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01
|
|
|
|
#define FRAME_CALLBACK_FLAG_CAMERA 0x05
|
|
|
|
#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class ICameraService;
|
|
|
|
class ICamera;
|
|
|
|
class Surface;
|
|
|
|
class Mutex;
|
|
|
|
class String8;
|
|
|
|
|
|
|
|
typedef void (*shutter_callback)(void *cookie);
|
|
|
|
typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
|
|
|
|
typedef void (*autofocus_callback)(bool focused, void *cookie);
|
|
|
|
typedef void (*error_callback)(status_t err, void *cookie);
|
|
|
|
|
|
|
|
class Camera : public BnCameraClient, public IBinder::DeathRecipient
|
|
|
|
{
|
|
|
|
public:
|
2008-12-18 02:05:43 +00:00
|
|
|
// construct a camera client from an existing remote
|
|
|
|
Camera(const sp<ICamera>& camera);
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
static sp<Camera> connect();
|
|
|
|
~Camera();
|
2008-12-18 02:05:43 +00:00
|
|
|
void init();
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
status_t reconnect();
|
2008-10-21 14:00:00 +00:00
|
|
|
void disconnect();
|
2009-01-10 01:51:23 +00:00
|
|
|
status_t lock();
|
|
|
|
status_t unlock();
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
status_t getStatus() { return mStatus; }
|
|
|
|
|
|
|
|
// pass the buffered ISurface to the camera service
|
|
|
|
status_t setPreviewDisplay(const sp<Surface>& surface);
|
2008-12-18 02:05:43 +00:00
|
|
|
status_t setPreviewDisplay(const sp<ISurface>& surface);
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
// start preview mode, must call setPreviewDisplay first
|
|
|
|
status_t startPreview();
|
|
|
|
|
|
|
|
// stop preview mode
|
|
|
|
void stopPreview();
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
// get preview state
|
|
|
|
bool previewEnabled();
|
|
|
|
|
2009-02-10 23:44:00 +00:00
|
|
|
// start recording mode, must call setPreviewDisplay first
|
|
|
|
status_t startRecording();
|
|
|
|
|
|
|
|
// stop recording mode
|
|
|
|
void stopRecording();
|
|
|
|
|
|
|
|
// get recording state
|
|
|
|
bool recordingEnabled();
|
|
|
|
|
|
|
|
// release a recording frame
|
|
|
|
void releaseRecordingFrame(const sp<IMemory>& mem);
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
// autoFocus - status returned from callback
|
|
|
|
status_t autoFocus();
|
|
|
|
|
|
|
|
// take a picture - picture returned from callback
|
|
|
|
status_t takePicture();
|
|
|
|
|
|
|
|
// set preview/capture parameters - key/value pairs
|
|
|
|
status_t setParameters(const String8& params);
|
|
|
|
|
|
|
|
// get preview/capture parameters - key/value pairs
|
|
|
|
String8 getParameters() const;
|
|
|
|
|
|
|
|
void setShutterCallback(shutter_callback cb, void *cookie);
|
|
|
|
void setRawCallback(frame_callback cb, void *cookie);
|
|
|
|
void setJpegCallback(frame_callback cb, void *cookie);
|
2009-02-10 23:44:00 +00:00
|
|
|
void setRecordingCallback(frame_callback cb, void *cookie);
|
|
|
|
void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
|
2008-10-21 14:00:00 +00:00
|
|
|
void setErrorCallback(error_callback cb, void *cookie);
|
|
|
|
void setAutoFocusCallback(autofocus_callback cb, void *cookie);
|
2009-02-10 23:44:00 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
// ICameraClient interface
|
|
|
|
virtual void shutterCallback();
|
|
|
|
virtual void rawCallback(const sp<IMemory>& picture);
|
|
|
|
virtual void jpegCallback(const sp<IMemory>& picture);
|
2009-02-10 23:44:00 +00:00
|
|
|
virtual void previewCallback(const sp<IMemory>& frame);
|
2008-10-21 14:00:00 +00:00
|
|
|
virtual void errorCallback(status_t error);
|
|
|
|
virtual void autoFocusCallback(bool focused);
|
2009-02-10 23:44:00 +00:00
|
|
|
virtual void recordingCallback(const sp<IMemory>& frame);
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
sp<ICamera> remote();
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
private:
|
|
|
|
Camera();
|
|
|
|
virtual void binderDied(const wp<IBinder>& who);
|
|
|
|
|
|
|
|
class DeathNotifier: public IBinder::DeathRecipient
|
|
|
|
{
|
|
|
|
public:
|
2008-12-18 02:05:43 +00:00
|
|
|
DeathNotifier() {
|
2008-10-21 14:00:00 +00:00
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
virtual void binderDied(const wp<IBinder>& who);
|
|
|
|
};
|
2008-12-18 02:05:43 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
static sp<DeathNotifier> mDeathNotifier;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
// helper function to obtain camera service handle
|
|
|
|
static const sp<ICameraService>& getCameraService();
|
|
|
|
|
|
|
|
sp<ICamera> mCamera;
|
|
|
|
status_t mStatus;
|
|
|
|
|
|
|
|
shutter_callback mShutterCallback;
|
|
|
|
void *mShutterCallbackCookie;
|
|
|
|
frame_callback mRawCallback;
|
|
|
|
void *mRawCallbackCookie;
|
|
|
|
frame_callback mJpegCallback;
|
|
|
|
void *mJpegCallbackCookie;
|
2009-02-10 23:44:00 +00:00
|
|
|
frame_callback mPreviewCallback;
|
|
|
|
void *mPreviewCallbackCookie;
|
|
|
|
frame_callback mRecordingCallback;
|
|
|
|
void *mRecordingCallbackCookie;
|
2008-10-21 14:00:00 +00:00
|
|
|
error_callback mErrorCallback;
|
|
|
|
void *mErrorCallbackCookie;
|
|
|
|
autofocus_callback mAutoFocusCallback;
|
|
|
|
void *mAutoFocusCallbackCookie;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
friend class DeathNotifier;
|
|
|
|
|
|
|
|
static Mutex mLock;
|
|
|
|
static sp<ICameraService> mCameraService;
|
2008-12-18 02:05:43 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|