blob: 44acce5dd0b6b43d6e451f8cb25ce8ff655e4da7 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -08003 * Copyright (C) 2008 HTC Inc.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07004 *
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#ifndef ANDROID_HARDWARE_CAMERA_H
19#define ANDROID_HARDWARE_CAMERA_H
20
21#include <ui/ICameraClient.h>
22
23namespace android {
24
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080025/*
26 * A set of bit masks for specifying how the received frames from preview are
27 * handled before the frame callback call.
28 *
29 * The least significant 3 bits of an "int" value are used for this purpose:
30 *
31 * ..... 0 0 0
32 * ^ ^ ^
33 * | | |---------> determine whether the callback is enabled or not
34 * | |-----------> determine whether the callback is one-shot or not
35 * |-------------> determine whether the frame is copied out or not
36 *
37 * For instance,
38 * 1. 0x00 disables the callback. In this case, copy out and one shot bits
39 * are ignored.
40 * 2. 0x01 enables a callback without copying out the recievied frames. A
41 * typical use case is the Camcorder application to avoid making costly
42 * frame copies.
43 * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
44 * use case is the Camera application.
45 * 4. 0x07 is enabling a callback with frame copied out only once. A typical use
46 * case is the Barcode scanner application.
47 */
48#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01
49#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02
50#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04
51
52// Typical use cases
53#define FRAME_CALLBACK_FLAG_NOOP 0x00
54#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01
55#define FRAME_CALLBACK_FLAG_CAMERA 0x05
56#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07
57
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070058class ICameraService;
59class ICamera;
60class Surface;
61class Mutex;
62class String8;
63
64typedef void (*shutter_callback)(void *cookie);
65typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
66typedef void (*autofocus_callback)(bool focused, void *cookie);
67typedef void (*error_callback)(status_t err, void *cookie);
68
69class Camera : public BnCameraClient, public IBinder::DeathRecipient
70{
71public:
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080072 // construct a camera client from an existing remote
73 Camera(const sp<ICamera>& camera);
74
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070075 static sp<Camera> connect();
76 ~Camera();
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080077 void init();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070078
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080079 status_t reconnect();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070080 void disconnect();
The Android Open Source Project27629322009-01-09 17:51:23 -080081 status_t lock();
82 status_t unlock();
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070083
84 status_t getStatus() { return mStatus; }
85
86 // pass the buffered ISurface to the camera service
87 status_t setPreviewDisplay(const sp<Surface>& surface);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080088 status_t setPreviewDisplay(const sp<ISurface>& surface);
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070089
90 // start preview mode, must call setPreviewDisplay first
91 status_t startPreview();
92
93 // stop preview mode
94 void stopPreview();
95
The Android Open Source Project27629322009-01-09 17:51:23 -080096 // get preview state
97 bool previewEnabled();
98
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070099 // autoFocus - status returned from callback
100 status_t autoFocus();
101
102 // take a picture - picture returned from callback
103 status_t takePicture();
104
105 // set preview/capture parameters - key/value pairs
106 status_t setParameters(const String8& params);
107
108 // get preview/capture parameters - key/value pairs
109 String8 getParameters() const;
110
111 void setShutterCallback(shutter_callback cb, void *cookie);
112 void setRawCallback(frame_callback cb, void *cookie);
113 void setJpegCallback(frame_callback cb, void *cookie);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800114
115 void setFrameCallback(frame_callback cb,
116 void *cookie,
117 int frame_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
118
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700119 void setErrorCallback(error_callback cb, void *cookie);
120 void setAutoFocusCallback(autofocus_callback cb, void *cookie);
121 // ICameraClient interface
122 virtual void shutterCallback();
123 virtual void rawCallback(const sp<IMemory>& picture);
124 virtual void jpegCallback(const sp<IMemory>& picture);
125 virtual void frameCallback(const sp<IMemory>& frame);
126 virtual void errorCallback(status_t error);
127 virtual void autoFocusCallback(bool focused);
128
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800129 sp<ICamera> remote();
130
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700131private:
132 Camera();
133 virtual void binderDied(const wp<IBinder>& who);
134
135 class DeathNotifier: public IBinder::DeathRecipient
136 {
137 public:
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800138 DeathNotifier() {
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700139 }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800140
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700141 virtual void binderDied(const wp<IBinder>& who);
142 };
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800143
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700144 static sp<DeathNotifier> mDeathNotifier;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800145
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700146 // helper function to obtain camera service handle
147 static const sp<ICameraService>& getCameraService();
148
149 sp<ICamera> mCamera;
150 status_t mStatus;
151
152 shutter_callback mShutterCallback;
153 void *mShutterCallbackCookie;
154 frame_callback mRawCallback;
155 void *mRawCallbackCookie;
156 frame_callback mJpegCallback;
157 void *mJpegCallbackCookie;
158 frame_callback mFrameCallback;
159 void *mFrameCallbackCookie;
160 error_callback mErrorCallback;
161 void *mErrorCallbackCookie;
162 autofocus_callback mAutoFocusCallback;
163 void *mAutoFocusCallbackCookie;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800164
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700165 friend class DeathNotifier;
166
167 static Mutex mLock;
168 static sp<ICameraService> mCameraService;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800169
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700170};
171
172}; // namespace android
173
174#endif
175