blob: fd851d9efcf1d2e7513b9d109091c4d0f7e6ce13 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (C) 2008 HTC Inc.
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#ifndef ANDROID_HARDWARE_CAMERA_H
19#define ANDROID_HARDWARE_CAMERA_H
20
21#include <ui/ICameraClient.h>
22
23namespace android {
24
25/*
26 * A set of bit masks for specifying how the received preview frames are
27 * handled before the previewCallback() 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 * WARNING:
38 * When a frame is sent directly without copying, it is the frame receiver's
39 * responsiblity to make sure that the frame data won't get corrupted by
40 * subsequent preview frames filled by the camera. This flag is recommended
41 * only when copying out data brings significant performance price and the
42 * handling/processing of the received frame data is always faster than
43 * the preview frame rate so that data corruption won't occur.
44 *
45 * For instance,
46 * 1. 0x00 disables the callback. In this case, copy out and one shot bits
47 * are ignored.
48 * 2. 0x01 enables a callback without copying out the received frames. A
49 * typical use case is the Camcorder application to avoid making costly
50 * frame copies.
51 * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
52 * use case is the Camera application.
53 * 4. 0x07 is enabling a callback with frame copied out only once. A typical use
54 * case is the Barcode scanner application.
55 */
56#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01
57#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02
58#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04
59
60// Typical use cases
61#define FRAME_CALLBACK_FLAG_NOOP 0x00
62#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01
63#define FRAME_CALLBACK_FLAG_CAMERA 0x05
64#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07
65
66class ICameraService;
67class ICamera;
68class Surface;
69class Mutex;
70class String8;
71
72typedef void (*shutter_callback)(void *cookie);
73typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
74typedef void (*autofocus_callback)(bool focused, void *cookie);
75typedef void (*error_callback)(status_t err, void *cookie);
76
77class Camera : public BnCameraClient, public IBinder::DeathRecipient
78{
79public:
80 // construct a camera client from an existing remote
James Dongf1a53142009-04-23 14:07:23 -070081 static sp<Camera> create(const sp<ICamera>& camera);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 static sp<Camera> connect();
83 ~Camera();
84 void init();
85
86 status_t reconnect();
87 void disconnect();
88 status_t lock();
89 status_t unlock();
90
91 status_t getStatus() { return mStatus; }
92
93 // pass the buffered ISurface to the camera service
94 status_t setPreviewDisplay(const sp<Surface>& surface);
95 status_t setPreviewDisplay(const sp<ISurface>& surface);
96
97 // start preview mode, must call setPreviewDisplay first
98 status_t startPreview();
99
100 // stop preview mode
101 void stopPreview();
102
103 // get preview state
104 bool previewEnabled();
105
106 // start recording mode, must call setPreviewDisplay first
107 status_t startRecording();
108
109 // stop recording mode
110 void stopRecording();
111
112 // get recording state
113 bool recordingEnabled();
114
115 // release a recording frame
116 void releaseRecordingFrame(const sp<IMemory>& mem);
117
118 // autoFocus - status returned from callback
119 status_t autoFocus();
120
121 // take a picture - picture returned from callback
122 status_t takePicture();
123
124 // set preview/capture parameters - key/value pairs
125 status_t setParameters(const String8& params);
126
127 // get preview/capture parameters - key/value pairs
128 String8 getParameters() const;
129
130 void setShutterCallback(shutter_callback cb, void *cookie);
131 void setRawCallback(frame_callback cb, void *cookie);
132 void setJpegCallback(frame_callback cb, void *cookie);
133 void setRecordingCallback(frame_callback cb, void *cookie);
134 void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
135 void setErrorCallback(error_callback cb, void *cookie);
136 void setAutoFocusCallback(autofocus_callback cb, void *cookie);
137
138 // ICameraClient interface
139 virtual void shutterCallback();
140 virtual void rawCallback(const sp<IMemory>& picture);
141 virtual void jpegCallback(const sp<IMemory>& picture);
142 virtual void previewCallback(const sp<IMemory>& frame);
143 virtual void errorCallback(status_t error);
144 virtual void autoFocusCallback(bool focused);
145 virtual void recordingCallback(const sp<IMemory>& frame);
146
147 sp<ICamera> remote();
148
149private:
150 Camera();
151 virtual void binderDied(const wp<IBinder>& who);
152
153 class DeathNotifier: public IBinder::DeathRecipient
154 {
155 public:
156 DeathNotifier() {
157 }
158
159 virtual void binderDied(const wp<IBinder>& who);
160 };
161
162 static sp<DeathNotifier> mDeathNotifier;
163
164 // helper function to obtain camera service handle
165 static const sp<ICameraService>& getCameraService();
166
167 sp<ICamera> mCamera;
168 status_t mStatus;
169
170 shutter_callback mShutterCallback;
171 void *mShutterCallbackCookie;
172 frame_callback mRawCallback;
173 void *mRawCallbackCookie;
174 frame_callback mJpegCallback;
175 void *mJpegCallbackCookie;
176 frame_callback mPreviewCallback;
177 void *mPreviewCallbackCookie;
178 frame_callback mRecordingCallback;
179 void *mRecordingCallbackCookie;
180 error_callback mErrorCallback;
181 void *mErrorCallbackCookie;
182 autofocus_callback mAutoFocusCallback;
183 void *mAutoFocusCallbackCookie;
184
185 friend class DeathNotifier;
186
187 static Mutex mLock;
188 static sp<ICameraService> mCameraService;
189
190};
191
192}; // namespace android
193
194#endif
195